MATLAB Answers

Brian Williams

Use string value of variable as function output target

Asked by Brian Williams
on 16 May 2012

I am trying to iteratively run a function, putting the output to a variable of the form 'CMi', where 'i' is an integer. I can easily work with variables of this form by running:

>>> varName = strcat('CM',i)

I am strugling, however, to put the value 'CMi' as the output for a function. In particular:

>>> [varName1, varName2] = function(inputs)

redefines my variable names, and:

>>> [strcat('CM',ii)] = function(inputs)

redefines strcat. How can I print the string value of varName as the target output variable name for a function? Thanks in advance for your assistance!




No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 16 May 2012
 Accepted answer

  1 Comment

Brian Williams
on 16 May 2012

Thanks Walter. The eval command works great. I'm going to take the wiki's advice and move away from such variable name construction as quickly as possible.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!