[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
dynamic list of variable names
From: |
John W. Eaton |
Subject: |
dynamic list of variable names |
Date: |
Fri, 16 Sep 2005 14:05:23 -0400 |
On 16-Sep-2005, Colin Ingram wrote:
| How does one create a dynamic list of variables names at runtime.
| So I'd like to do something like
|
| nr = some_function(x,y)
| for i = 1:nr
| ["some_variable_name" , "i"] = someother_function (i)
| end
|
| Which you obviously can't do since you can't have string
| concatenation on the left side of the assignment operator.
|
| It seams like I might be able to work something up using a variable
| list of return values from a function but I can't see how to do
| this. Is it even possible or am I stuck using a structure or cell
| to hold my data?
You can do it with eval, but it is generaly considered bad form to
introduce new variables this way. You are better off using a cell
array or structure.
jwe
-------------------------------------------------------------
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
-------------------------------------------------------------