transform matrix nx3 to cell nx2

조회 수: 1 (최근 30일)
Pilar Julieta Tagliero
Pilar Julieta Tagliero 2021년 6월 23일
댓글: Pilar Julieta Tagliero 2021년 6월 24일
Hello
Starting from this 4x3 matrix:
O =
0 10 0
0 10 0
0.1 2 3
0.1 2 3
How could I obtain this cell?
P =
4×2 cell array
{[0 10]} {[0]}
{[0 10]} {[0]}
{[0.1 2]} {[3]}
{[0.1 2]} {[3]}
In this case the number of rows is fixed n=4, but I need n to be a variable.
Thanks in advance!!

채택된 답변

Jan
Jan 2021년 6월 23일
편집: Jan 2021년 6월 23일
O = [ 0 10 0; ...
0 10 0; ...
0.1 2 3; ...
0.1 2 3];
P = mat2cell(O, ones(size(O, 1), 1), [2, 1])
P = 4×2 cell array
{[ 0 10]} {[0]} {[ 0 10]} {[0]} {[0.1000 2]} {[3]} {[0.1000 2]} {[3]}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by