store variables with ascending names in array

1 次查看(过去 30 天)
Hello,
Can somebody help me with that?
I am using the PDE toolbox in matlab and I have to create ns and sf variables using the following code.
ns = char('R1','R2','R3','R4','R5','R6','R7');
ns = ns';
sf = 'R1+R2+R3+R4+R5+R6+R7';
It is easy when you have to do it 7 times but I need to do it 12500!!! I believe I need to create variables with ascending names and store them in ns and then add them in sf but I cannot do it!
Many thanks
  1 个评论
Evita
Evita 2017-6-16
Hello,
Many thanks for that but it does not help a lot because although it creates the variables, I need to store them in an array with dimensions 1*12500.
Array=[R1 R2 R3 .... R12500]
In your example the answer is a single cell with R1R2R3R4...R12500 as a single value.

请先登录,再进行评论。

采纳的回答

MathReallyWorks
MathReallyWorks 2017-6-16
Hello,
Use this for creating as many variables as you want:
for i=1:10 %I have taken 10 just for example and explanation. You can take 12500.
s1 = 'R';
s2 = num2str(i);
s = strcat(s1,s2)
end
Copy and paste above code on command window to understand properly.
  1 个评论
Evita
Evita 2017-6-16
FYI I found it!!! Many thanks again
ns=cell(1,numSub);
for i=1:numSub;
s1=['R'];
s2=[num2str(i)];
temp=strcat(s1,s2);
ns{1,i}=temp;
end
ns=char(ns);
ns=ns';

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by