I created my own handle Class called CModelDeficit, and now want to create an array of this objects with slight difference in parameters:
function M = meta(obj) M = []; p = obj.getParameters(); %this gives me parameters of initial object
p(3) = 0.1; p(4) = 0.1; M = [M,CModelDeficit(p)]; %CModelDeficit(p) is a constructor of a class with parameters 'p'
p(3) = 0.2; p(4) = 0.2; M = [M, CModelDeficit(p)]; end
Calling this function returns me a 1×2 CModelDeficit, just as i wanted it.
But when i try make the very same process using for-loops:
function M = meta2(obj) M = []; p = obj.getParameters(); for i = 1:0.1:0.9 for j = 1:0.1:0.9 p(3) = i; p(4) = j; M = [M,CModelDeficit(p)]; end end end
returns me just an empty vector.
It seems for me very confusing and illogical, that they have different behaviour.
I always thought, that, in such context, for-loop is a nicer way to write functions, then just typing nearly same thing 81 times.
I would appreciate a detailed explanation about inner structure of for-loops in this circumstances.
Thank You,
Pavel Bykov
Best Answer