[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to use a variable for naming another variable in octave
From: |
John W. Eaton |
Subject: |
Re: how to use a variable for naming another variable in octave |
Date: |
Mon, 10 Nov 2008 18:08:54 -0500 |
On 10-Nov-2008, Søren Hauberg wrote:
| man, 10 11 2008 kl. 22:46 +0100, skrev Luca Penasa:
| > Is possible to use a variable for naming another one in an iterative
| > process like in bash language? I would like something like this:
| >
| > for i = 1:50
| > result_$i = function(data,i);
| > endfor
|
| something like
|
| for i = 1:50
| eval (sprintf ("result_%d = function (data, %d);", i, i);
| endfor
|
| should work, but I haven't tested it.
As Søren says, that should work, but you should ask yourself why you
want to do this. Unless you really need the variables to be named
like this, I think it would be better to avoid the call to eval and
store the results in a cell array:
results = cell (50, 1);
for i = 1:50
results{i} = function (data, i);
endfor
jwe