Store every n rows of a matrix in cell

조회 수: 2 (최근 30일)
pavlos
pavlos 2018년 9월 16일
댓글: Gargi Majumdar 2021년 8월 21일
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

채택된 답변

Rik
Rik 2018년 9월 16일
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
Rik
Rik 2018년 9월 19일
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.
Gargi Majumdar
Gargi Majumdar 2021년 8월 21일
I used the followig after using the above code
for i = 1:111;
F(:,i) = B{i,1};
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by