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

8 vues (au cours des 30 derniers jours)
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 commentaire
Matt Fig
Matt Fig le 4 Oct 2012
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...

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 3 Oct 2012
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 commentaire
Walter Roberson
Walter Roberson le 4 Oct 2012
Note that if your goal is just to display it with different numbers of elements per line, then that is feasible.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by