help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question about making variables


From: Juan Pablo Carbajal
Subject: Re: A question about making variables
Date: Tue, 24 Jul 2012 17:26:56 +0200

On Tue, Jul 24, 2012 at 5:14 PM, vilsu <address@hidden> wrote:
> Hello again
>
> I approach you as I know nothing about programming. I ask you a question you
> probably feel is the basic thing to learn in lesson one:
>
> I have a "for" loop in wich "i" ranges from 1 to say 5000.
>
> How can I make as many variables with the help of "i" to keep them in Octave
> memory?
>
> Yours vilsu
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/A-question-about-making-variables-tp4631642.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

Hi,
There may be others ways of doing this, and probably it is not
recommended to do this. Anyway, one way to generate variables in a
loop is

for i=1:500
    eval(["var" num2str(i) "= 0"]);
endfor

This creates 500 variables named "var1", "var2", ... "var500" each one
containing a value 0.

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]