필터 지우기
필터 지우기

store variables with ascending names in array

조회 수: 2 (최근 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 CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by