changing the variable name in a FOR loop

  • Follow


I work with double variables with different names and dimensions and would like to manipulate them by using FOR loops.

The strategy I want to give up:
    variable0=update(variable0,rate);
    variable1=update(variable1,rate);
    variable2=update(variable2,rate);
    variable3=update(variable3,rate);
    .
    .
    variableN=update(variableN,rate)

The FOR strategy I'd like to use
    for I=1:N
        variable[I]=update(variable[I],rate);
    end

Do you know how to implement this strategy of changing the variable name on a FOR loop?

Other possibility could be access a string variable containing the variable names... This solution would be very interesting too...

Thank you
0
Reply R 11/24/2009 4:20:24 PM

variable = cell(n,1);
% Do stuff to fill cell, then:


for ii = 1:n
variable{ii} = update(variable{ii},rate);
end
0
Reply Matt 11/24/2009 4:31:20 PM


"R P" <rpavao@colband.com.br> wrote in message 
news:heh148$q6$1@fred.mathworks.com...
>I work with double variables with different names and dimensions and would 
>like to manipulate them by using FOR loops.
>
> The strategy I want to give up:
>    variable0=update(variable0,rate);

*snip*

See Q4.6 in the newsgroup FAQ for alternate methods that you should use 
instead of dynamic variable names.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ 


0
Reply Steven 11/26/2009 11:55:44 PM

2 Replies
1201 Views

(page loaded in 0.051 seconds)

Similiar Articles:













7/22/2012 2:09:55 PM


Reply: