help-octave
[Top][All Lists]
Advanced

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

Re: Creating "sequential variable names"


From: AlbFrigerio
Subject: Re: Creating "sequential variable names"
Date: Mon, 18 Oct 2010 06:55:35 -0700 (PDT)

Thank you so much Andy and Søren, your help was very fast and I got what I
wanted to.

Søren, you are completely right, but I'm not (yet) so crazy to create 100
variables instead of using a vector :) . I just proposed an example, I just
needed to know ho to create sequential names.

Thanks again,
  Alberto


Søren Hauberg wrote:
> 
> Hi
> 
> man, 18 10 2010 kl. 06:21 -0700, skrev AlbFrigerio:
>> Hello world, I've got a problem in defyining "sequential name variable" .
>> I
>> would like to create name variables such as b1, b2, b100 and to assign
>> them
>> values, e.g. b1=1, b2=2, ... , b100 = 100. I would obviously not to
>> assign
>> every variable at once, I'd like to use a for loop similar to
>> 
>> for i = 1:100
>> bi=i;
>> endfor
>> 
>> This is not the right answer, but I don't know how to create sequentially
>> name variables like b1, b2, etc. I could create a string name
>> strcat("b",nu2str(i)) , but I don't solve my problem. I got the same
>> problem
>> using b_i = i, does anyone have an idea?
> 
> You can this using the 'eval' function, i.e.
> 
>   for i = 1:100
>     eval (sprintf ("b%d = %d;", i, i));
>   endfor
> 
> but are you really sure that's what you want? Why not just create an
> array with the values you need? That is,
> 
>   b = 1:100;
> 
> and then index that array 'b (i)' when you need the value.
> 
> Søren
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/Creating-sequential-variable-names-tp3000216p3000287.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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