필터 지우기
필터 지우기

how to cell array all data into a matrices

조회 수: 1 (최근 30일)
singh
singh 2015년 4월 29일
댓글: Star Strider 2015년 4월 29일
suppose i have a cell array
a={{1,2,3};12;{21,32,43}};
how to get all data in single matrix
b=[1,2,3,12,21,32,43]'

채택된 답변

Star Strider
Star Strider 2015년 4월 29일
편집: Star Strider 2015년 4월 29일
Use horzcat and cell2mat:
b = cell2mat(horzcat(a{:}))
produces:
b =
1 2 3 12 21 32 43
I didn’t initially see the transpose operator. To get it as a column vector, add the transpose:
b = cell2mat(horzcat(a{:}))'
  댓글 수: 2
singh
singh 2015년 4월 29일
star ur genius
A =
[1x4 double] [19] [1x4 double] [1x4 double]
A{:}
ans =
1 2 14 16
ans =
19
ans =
6 12 15 20
ans =
3 4 7 17
how to get it into single matrix
B=[1,2,14,16,19,6,12,15,20,3,4,7,17]
strider plz check
Star Strider
Star Strider 2015년 4월 29일
I wish! Thank you for the compliment.
Slightly different with ‘A’ here, since it is a cell array of vectors and not a cell array of cells, so we do not need cell2mat this time:
B = horzcat(A{:})
produces:
B =
1 2 14 16 19 6 12 15 20 3 4 7 17

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

추가 답변 (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