How to convert a cell array (nx1) with different size of elements in each cell to a matrix?
조회 수: 2 (최근 30일)
이전 댓글 표시
Suppose I have a nx1 cell as follows:
X = [0,160,208]
[272,132]
[1272,133]
[22724,310]
[27516,312]
[30424,374,687]
[32262,437]
[36288,299,574,690]
[47884,637]
[53542,425]
[54494,633]
[58420,77]
[62800,461]
[72252,239]
[78429,46]
I want something like:
newX = [ 0 160 208
272 132
1272 133
22724 310
27516 312
30424 374 687
32262 437
36288 299 574 690
47884 637
53542 425
54494 633
58420 77
62800 461
72252 239
78429 46 ]
That is each element of the cell X should be stored in new column of the newX.
(I have tried something with pre-defining the new array but I do not want any NaN or Zeros after I pre-define it. )
Your help will be greatly appreciated as I am very new to Matlab.
Thank you
댓글 수: 1
Matt Fig
2012년 10월 4일
So if you do not want a nan or a zero in the non-used spots, what do you want there? MATLAB will not allow an empty element of a numeric array. If an array is numeric, this means that each element of the array is numeric...
답변 (1개)
Walter Roberson
2012년 10월 3일
That is not possible in MATLAB. MATLAB does not support "ragged arrays". If you want an array, then the unused locations must be populated with something
댓글 수: 1
Walter Roberson
2012년 10월 4일
Note that if your goal is just to display it with different numbers of elements per line, then that is feasible.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!