How to make a cell array of cell arrays
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi,
How does one make a cell array of cell array in Matlab ? Let's A = (1:70), how can I transform this into a 14x1 cell array for which every cell contains 5 numbers ?
Thank you
댓글 수: 1
Adam Danz
2019년 8월 6일
Ha! You got 2 answers at almost the same time with almost the same variable names and the same explanation of terminology.
채택된 답변
Adam Danz
2019년 8월 6일
편집: Adam Danz
2019년 8월 6일
"how can I transform this into a 14x1 cell array for which every cell contains 5 numbers"
What you're describing is a cell array of vectors, not a cell array of cells.
c = mat2cell(reshape(A,5,14),5,ones(1,14)); % For column vectors
or
c = mat2cell(reshape(A,5,14)',ones(1,14),5); % For row vectors
추가 답변 (2개)
the cyclist
2019년 8월 6일
Here is one way:
A = 1:70;
C = cell(14,1);
for ii = 1:14
C{ii} = A(5*ii-4:5*ii);
end
To be clear on terminology (and what you actually want) ... this will be a cell array of numeric vectors, not a cell array of cell arrays.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!