How to store rows of matrix into cell array?
조회 수: 44 (최근 30일)
이전 댓글 표시
Hello Sir,
How can i store different rows of matrix to cells in an cell array. For example: I have a matrix name 'tab' with 5 rows and i want to store every row of 'tab' into different cells of 'v_r' cell array.
tab = magic(5);
v_r = cell(1,5);
Output should be:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/933939/image.jpeg)
댓글 수: 0
채택된 답변
Image Analyst
2022년 3월 20일
편집: Image Analyst
2022년 3월 20일
Try this:
tab = magic(5);
v_r = cell(1,5);
for row = 1 : size(tab, 1)
v_r{row} = tab(row, :);
end
v_r % Show in command window
By the way, this just complicates things and is less efficient than just leaving them in a matrix. I would not recommend putting the rows into a cell array.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!