I must be missing something really simple because this doesnt seem like it should be this hard.
This code is correct:
clear all
whatever = @(x) deal(max(x), size(x));
input = randn(1,1000);
[a b] = whatever(input)
However, what I really want to do is something like this:
clear all
whatever = @(x) deal(q = 3; q*max(x), size(x));
input = randn(1,1000);
[a b] = whatever(input)
Why does this break? I cant define q inside the function?? The whole reason I want to use anonymous functions is so that I can actually do multiple lines of code within them, and then return an answer. I suppose the last statement of an anonymous function is what is returned, but how do I define variables within them? I dont want to define q before the definition of the anonymous function.
Thanks.
You cannot declare variables inside an anonymous function, because it must be constructed from an expression, i.e.:
handle = @(arglist)exprIf you want readability, define
qoutside the function, like this: