如何使用变量创建 MATLAB 元素?
我有以下代码:
x = textread('/home/data/data.txt','%s')
for i=1:50
S=load(['/home/data/',x{i},'_file.mat'])
info_',x{i},' = strcat(S.info1, S.info2)
end
当然,最后一行 (info_',x{i},' = strcat(S.info1, S.info2)
)不起作用。似乎不可能使用变量来创建 MATLAB 元素。这是正确的还是我只是在这里做错了什么?有一个优雅的解决方法吗?
Possible Duplicates:
How to concatenate a number to a variable name in MATLAB?
MATLAB: How can I use a variables value in another variables name?
I have the following code:
x = textread('/home/data/data.txt','%s')
for i=1:50
S=load(['/home/data/',x{i},'_file.mat'])
info_',x{i},' = strcat(S.info1, S.info2)
end
Of course, the last line (info_',x{i},' = strcat(S.info1, S.info2)
) doesn't work. It just doesn't seem to be possible to use a variable to create MATLAB elements. Is this right or am I just doing something wrong here? Is there an elegant workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要类似的东西吗
?
如果是这样,我可以阻止您这样做,请参阅:http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
Do you want something like
?
If so, could I discourage you from doing so, see: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
请尝试以下操作:
Try the following: