Is it possible to copy the elements of a matrix to a set of variable names ?
조회 수: 1 (최근 30일)
이전 댓글 표시
Given is a matrix A of size [1x6]. What I want is to copy the elements of A to a set of variable names [a,b,c,d,e,f], so that
a = A(1);
b= A(2)
a.s.o.
I tried
[a,b,c,d,e,f] = deal(A);
But this copies not the elements but the hole matrix A into each variable.
Any help is much appreciated.
댓글 수: 0
채택된 답변
Walter Roberson
2013년 3월 13일
편집: Walter Roberson
2013년 3월 13일
Acell = num2cell(A);
[a,b,c,d,e,f] = deal(Acell{:}); %older MATLAB
[a,b,c,d,e,f] = Acell{:}; %newer MATLAB
추가 답변 (1개)
Azzi Abdelmalek
2013년 3월 13일
편집: Azzi Abdelmalek
2013년 3월 13일
A=rand(1,6)
s='abcdef'
for k=1:numel(s)
assignin('base',s(k),A(k))
end
댓글 수: 6
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!