create variable with name from string?

John W. Eaton jwe at bevo.che.wisc.edu
Sun Mar 30 09:08:53 CDT 2008


On 30-Mar-2008, Stefan Pofahl wrote:

|   eval (sprintf ([nameofvariable, "= ", num2str(numberoffruits, "%i")]));

Since you're using sprintf anyway, you can simplify this to be

  eval (sprintf ("nameofvariable = %d", numberoffruits"));

but I think it is generally best to avoid generating new variables
with eval.

jwe


More information about the Help-octave mailing list