store variables with ascending names in array

1 回表示 (過去 30 日間)
Evita
Evita 2017 年 6 月 16 日
コメント済み: Evita 2017 年 6 月 16 日
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 Center および File ExchangeEigenvalue Problems についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by