How to convert a cell array (nx1) with different size of elements in each cell to a matrix?

6 次查看(过去 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
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
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

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by