String to variable name MATLAB

前端 未结 1 483
鱼传尺愫
鱼传尺愫 2020-11-30 16:05

If for instance I have a variable xa=2, and then I construct a string by joining \'x\' and \'a\', how can I make this new string have the value 2?

xa=2;
var=         


        
1条回答
  •  离开以前
    2020-11-30 16:20

    Use eval():

    var = eval(strcat('x','a'));
    

    It will "evaluate" the string 'xa' and translate it to the value of the variable xa.

    Source : MATLAB documentation

    0 讨论(0)
提交回复
热议问题