Store every n rows of a matrix in cell

5 views (last 30 days)
pavlos
pavlos on 16 Sep 2018
Commented: Gargi Majumdaron 21 Aug 2021
Hello,
Please help me with the following:
Consider a 11808x1 matrix A.
I need to take every 96 elements and store them in cell B.
The first element of B would have 1-96 elements of A, the second would have 97-192, etc.
Thank you.
Best, Pavlos

Accepted Answer

Rik
Rik on 16 Sep 2018
You can do that with the mat2cell function.
A=rand(11808,1);
k=96;
B=mat2cell(A,k*ones(size(A,1)/k,1),1);
Note that this doesn't work for splits that are not equal size (so a group size of 5 doesn't work).
2 Comments
Gargi Majumdar
Gargi Majumdar on 21 Aug 2021
I used the followig after using the above code
for我= 1:111;
F(:,i) = B{i,1};
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!