How to store rows of matrix into cell array?
52 views (last 30 days)
Show older comments
ANURAG DEEPAK
on 20 Mar 2022
Commented: ANURAG DEEPAK
on 20 Mar 2022
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:
0 Comments
Accepted Answer
Image Analyst
on 20 Mar 2022
Edited: Image Analyst
on 20 Mar 2022
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 Comments
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!