How to create vectors from a cell array?
조회 수: 25 (최근 30일)
이전 댓글 표시
I have a cell array consisting of 3 cells (1x10, 1x15, 1x20). How can I efficiently create 3 vectors?
댓글 수: 1
답변 (2개)
Adam
2017년 7월 3일
편집: Adam
2017년 7월 3일
[a,b,c] = myCell{:};
Not advisable if the number of vectors you want to create escalates to the state that you are next going to ask how you name then a1, a2, a3, etc, but for just extracting an explicit number of outputs the above should work.
Image Analyst
2017년 7월 3일
Use deal():
% Setup: Make cell array consisting of 3 cells (1x10, 1x15, 1x20).
ca = {ones(1,10), rand(1,15), randi(9, 1, 20)}
celldisp(ca); % Display it.
% Make vectors
[v1, v2, v3] = deal(ca{:})
or simply assign the 3 vectors
v1 = ca{1};
v2 = ca{2};
v3 = ca{3};
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!