I tried to determine:
f = @(x) d*x
where d is the variable defined earlier, say d = 2. My goal is to return it:
@(x) 2*x
However, MATLAB returns:
@(x) d*x
The reason I did this was to define a series of function handles in a for loop, for example.
q = cell(n, 1);
for i = 1:n
q{i} = @(y) sum(y(1:i));
end
Is it possible to define an array of function descriptors that use indexes in the definitions of anonymous functions?
source
share