【发布时间】:2013-01-18 16:15:07
【问题描述】:
我是 MATLAB 的初学者,我希望我能在这个不错的网站上找到帮助(再次 :))。 它是关于一系列个体的模型预测结果。因此,我有一系列 变量(包含每个个体的基本结果)及其命名法不同 仅在第一部分..e,g:
Mike 结果保存为:Mike_Sim_V_software1 亚当结果另存为:Adam_Sim_V_sofwtare1 莎拉结果另存为:Sarah_Sim_V_sofwtar1 等等……
我已经有了名字列表 ['Mike','Adam','Sarah', etc.] 和 ID(% 保存在名为:idx 的变量中)
因为我想执行一系列与上述所有变量(结果变量)相似的计算, 由于我的变量名称仅在第一部分有所不同,因此我想编写一个这样的循环函数:
for idx=1:80
x= Indi_All {idx,1} (1,1)
% idx: is the Individual IDs ... 80 is the total number of individuals
% Indi_All is a cell array containing the basic info, IDs and demographics..
here x will get the initial part of the variables names e.g. 'Mike' or 'Adam'
Indi_Results {idx,1} = x
Indi_Results {idx,2} = prctile (x_Sim_V_software1', (5))
Indi_Results {idx,2} = x_5P_software1'
Indi_Results {idx,3} = prctile (x_Sim_V_software1', (10))
Indi_Results {idx,3} = x_10P_software1'
Indi_Results {idx,4} = prctile (x_Sim_V_software1', (25))
Indi_Results {idx,4} = x_25P_software1'
Indi_Results {idx,5} = prctile (x_Sim_V_software1', [50])
Indi_Results {idx,5} = x_Median_software1'
Indi_Results {idx,6} = prctile (x_Sim_V_software1', (75))
Indi_Results {idx,6} = x_75P_software1'
Indi_Results {idx,7} = prctile (x_Sim_V_software1', (90))
Indi_Results {idx,7} = x_90P_software1'
Indi_Results {idx,8} = prctile (x_Sim_V_software1', [95])
Indi_Results {idx,8} = x_95P_software1'
% the code and calculations go even more and more ...
end
所以专家们可以看到...... x 将在代码(右列)中被识别为“x”,而不是我真正想要的意思,即变量 x 包含一个字符串值,如:'迈克'..
我的问题是:
1) 我可以解决这个问题吗?是否有任何函数可以从两个不同的字符串构造变量的名称?!所以也许类似于 num2str 的东西,但要在字符串中添加字符串! 换句话说,将变化部分'Mike','Adam'等添加到不变部分'_Sim_V_software1'以获得我可以在循环函数中使用的变量?!
我不知道...我觉得我的问题很愚蠢,但不知怎的,我为此花了很多时间,但它并没有按照我想要的方式工作! 希望这与我的大脑已经知道周末即将开始的事实无关:)
很高兴收到您的来信,并在此先感谢您...!
【问题讨论】:
标签: string matlab variables loops