How to convert from a matrix to a cell?

Given matrix is
A=[1 2 3 4 5 6 7 8; 9 10 11 12 13 14 15 16];
and output is
B={[1 2 3 4],[5 6 7 8];[9 10 11 12],[13 14 15 16]};
How can I do that?

 Accepted Answer

Use the mat2cell function:
A=[1 2 3 4 5 6 7 8; 9 10 11 12 13 14 15 16];
B = mat2cell(A, [1 1], [4 4]);
B11 = B{1,1} % Check Output
B22 = B{2,2} % Check Output

2 Comments

Thank you so much!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Asked:

SM
on 17 Jul 2020

Commented:

on 19 Jul 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!