1

I'm using arrayfun to plot the result of a custom function, which does some logic, look-ups, and calculations. My original call looked similar to this:

plot(x, arrayfun(@Q, x.^2, someNumericVariable));

This worked great. However, in addition to the someNumericVariable parameter, I also wanted to add another parameter, someStringVariable, so I changed it to this:

plot(x, arrayfun(@Q, x.^2, someNumericVariable, someStringVariable));

However, when trying to use this, I get an error:

error: arrayfun: dimensions mismatch

I'm guessing that this happens due to this line in the GNU Octave documentation:

If given more than one array input argument then all input arguments must have the same sizes (https://www.gnu.org/software/octave/doc/interpreter/Function-Application.html)

So I assume that the string I'm trying to pass is being treated as an array, which has different dimensions than the numeric constant value?

If this is so, are there any workarounds that I can do while keeping the code syntactically concise?

1 Answer 1

1

One workaround that would work in MATLAB would be:

plot(x, arrayfun(@(u,v) Q(u,v,someStringVariable), x.^2, someNumericVariable));
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, that did the trick! So I can read more about it in the MATLAB/Octave documentation, what is that syntax called?
@acee It is an anonymous function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.