For Programmers: Free Programming Magazines  


Home > Archive > Matlab > January 2008 > variable as an vector









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author variable as an vector
elle

2008-01-13, 7:26 pm

hello,

i want to work with variables named test1, test2, test3...an so on.
is it possible to do in matlab something like that:

for i=1:1:10
test'i'=i+354
end

and at least to save every variable ?
Thanks a lot!
elle
Walter Roberson

2008-01-13, 7:26 pm

In article <13094609.1200245310042.JavaMail.jakarta@nitrogen.mathforum.org>,
elle <dermannweg@gmx.net> wrote:

>i want to work with variables named test1, test2, test3...an so on.
>is it possible to do in matlab something like that:


>for i=1:1:10
>test'i'=i+354
>end


>and at least to save every variable ?


Yes, but it is strongly recommended that you do not do that.
Instead,

test = cell(1,10);
for i = 1:10
test{i} = i+354;
end

This will result in a single array named test, but test{k} can be
any datatype; e.g., test{2} might be a character string and
test{5} might be a complex array. If all of the elements you wish to
save are the same size and same data type, then a plain array would
normally be a better choice.
--
"Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us." -- Ecclesiastes
Steven Lord

2008-01-13, 7:26 pm


"elle" <dermannweg@gmx.net> wrote in message
news:13094609.1200245310042.JavaMail.jakarta@nitrogen.mathforum.org...
> hello,
>
> i want to work with variables named test1, test2, test3...an so on.
> is it possible to do in matlab something like that:


Possible? Yes. Recommended? No.

See question 4.6 in the newsgroup FAQ:

http://matlabwiki.mathworks.com/MATLAB_FAQ

--
Steve Lord
slord@mathworks.com


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com