help-octave
[Top][All Lists]
Advanced

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

Re: Creating "sequential variable names"


From: Søren Hauberg
Subject: Re: Creating "sequential variable names"
Date: Mon, 18 Oct 2010 15:32:58 +0200

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



reply via email to

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