필터 지우기
필터 지우기

save matrices of the sequential names in cell array

조회 수: 1 (최근 30일)
abbas hasan
abbas hasan 2014년 9월 5일
댓글: abbas hasan 2014년 9월 5일
hi all,
i have question about matrices of the sequential names in cell array with for loop, the matrices named like this A1,A2,A3,....... and so on.
i used this code
for i = 1:5 eval(['A' num2str(i) '=i*ones(2*i,2*i)']); C{i}=(['A', num2str(i)]); end
but i get in the cell only the char of matrix with out the value inside it.
i will be grateful to any help.

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 9월 5일
Why everybody wants to put the index into the variable name? That's exactly how you not profit from Matlab's strengths.
I guess you want to have something like
A=cellfun(@(x) x*ones(2*x),num2cell(1:5),'uniform',false);
  댓글 수: 1
abbas hasan
abbas hasan 2014년 9월 5일
thanks a lot, thanks a lot , this function work fine.

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

추가 답변 (1개)

Iain
Iain 2014년 9월 5일
Why not just use cell arrays?
for i =1:5
A{i} = i*ones(2*i,2*i);
C{i} = A{i};
end
But if you insist on using eval,
eval(['C{i} = A' num2str(i) ';']) or...
C{i} = eval(['A' num2str(i) ';'])

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by