[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: parameterized variable tmp1=2, tmp2=4
From: |
John van Baar |
Subject: |
Re: parameterized variable tmp1=2, tmp2=4 |
Date: |
Wed, 11 Apr 2001 11:44:15 +0200 (CEST) |
>| I am intending to increment the name of the variable in a loop.
>| The desired output is:
>| tmp1=2
>| tmp2=4
>|
>| using
>|
>| for i=1:2
>| sprintf('tmp%d',i)=2*i
>| endfor
>|
>| sprintf('tmp%d',i) gives "tmp1"
>| sprintf('tmp%d',i)=1 gives "string type invalid as index value"
>| How can this problem be solved or where can I find the solution?
>|
>| John van Baar
>
>[Try eval (sprintf ("tmp%d = %f;", i, val)); or similar. --jwe]
>
It works, thanks!
example:
octave:1> i=2;
octave:2> val=10;
octave:3> eval (sprintf ("tmp%d = %f;", i, val));
octave:4> eval (sprintf ("tmp%d = %f", i, val));
tmp2 = 10
octave:5> tmp2
tmp2 = 10
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: parameterized variable tmp1=2, tmp2=4,
John van Baar <=