字符串到变量名MATLAB [英] String to variable name MATLAB

查看:559
本文介绍了字符串到变量名MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有一个变量xa = 2,然后通过连接"x"和"a"来构造一个字符串,那么如何使这个新字符串的值为2?

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=strcat('x','a');

其结果是var = xa,但我想要的是var = 2.

The result of this is var=xa, but what I want is var=2.

谢谢

推荐答案

使用eval():

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

它将求值"字符串'xa'并将其转换为变量xa的值.

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

来源: MATLAB文档

这篇关于字符串到变量名MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆