# String problem

조회 수: 4 (최근 30일)
Raviteja 2011년 9월 7일
I have the following code
Lev=7;
for i=1:Lev
str=strcat('A',int2str(i));
for j=1:3
str(j,:)=squeeze(Atr(i,j,:));
end
end
This program showing erros like
??? Subscripted assignment dimension mismatch.
Error in ==> attractor_test at 80
str(j,:)=squeeze(Atr(i,j,:));
Actually, I want to assigne names in run time of the program execution. In the above code str have to take names like str ---> A1, A2, A3, ...A7 and store values in A1, A2, A3 ....A7 respectively..
How to do that in matlab ?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Bjorn Gustavsson 2011년 9월 7일
That is usually a bat thing to do. There is a busload of questions like this, and a good explanation in FAQ-s everywhere and the matlab newsgroup.
What I suggest you do instead is to use cell-arrays:
Lev = 7;
for i1 = 1:Lev
str = strcat('A',int2str(i1));
for j2 = 1:3
A{i1}(j2,:) = squeeze(Atr(i1,j2,:));
end
end
Also it is nice to avoid i and j as loop variables, sooner or later you'll get them jumbled with the imaginary i = (-1)^(1/2).
HTH
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Andrei Bobrov 2011년 9월 7일
n = size(Atr,1)
A = cell(n,1);
for i1 = 1:n
A{i1} = squeeze(Atr(i1,:,:));
end
OR
n =size(Atr)
A = mat2cell(reshape(permute(Atr,[3 2 1]),n(3),[])',ones(n(1)*n(2),1),n(3))
OR
n = size(Atr,1);
A = arrayfun(@(i1)squeeze(Atr(i1,:,:)),1:n,'un',0);

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by