Converting a numeric array to a cell array containing vectors

조회 수: 1 (최근 30일)
Andrew
Andrew 2011년 6월 5일
Hi,
Is there a way to convert a numeric array to a cell array of vectors? For example, suppose I have the following:
A=[1 1 1 2 2 2 3 3 3; 4 4 4 5 5 5 6 6 6];
And now suppose that I want to partition each row into vectors of size 1 by 3 and store these in a cell array. Effectively, I would like to obtain the cell array that is alternatively, manually given by the following:
B={[1 1 1],[2 2 2],[3 3 3];[4 4 4],[5 5 5],[6 6 6]}
Is there any way to do this automatically, assuming 1 by 3 vectors?
Thank you very much.
Andrew DeYoung
Carnegie Mellon University

채택된 답변

Matt Fig
Matt Fig 2011년 6월 5일
mat2cell(A,[1 1],[3 3 3])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by