필터 지우기
필터 지우기

put each column of a matrix into different cells

조회 수: 7 (최근 30일)
ARN
ARN 2020년 5월 11일
편집: Mehmed Saad 2020년 5월 11일
I have a matrix of size (4x4)
a = [1 2 3 4; 123 4 5 6; 52 5 4 7; 2 5 8 7];
b = mat2cell(a, ?)
I want b to be a {4x1} or {1x4} cell where every cell contains the column values of matrix
b = cell{1,:} = [1; 123; 52; 2] , cell{2,:} = [2 ; 4 ; 5 ; 5] and so on. but i am not being able to figure out mat2cell input parameters

채택된 답변

Mehmed Saad
Mehmed Saad 2020년 5월 11일
편집: Mehmed Saad 2020년 5월 11일
Use num2cell. it is easy
a = [1 2 3 4; 123 4 5 6; 52 5 4 7; 2 5 8 7];
b = num2cell(a,1)
b =
1×4 cell array
{4×1 double} {4×1 double} {4×1 double} {4×1 double}

mat2cell

is usefulll for other purpose
b = mat2cell(a.',[1 1 1 1])
b =
1×4 cell array
{4×1 double} {4×1 double} {4×1 double} {4×1 double}

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by