Convert cell array to an array, when the size of the cells is different

Hi all,
I have a cell array like this A={ [0 0 0 0] ; [1 1] ;[2] }
Is it possible to convert it in an array? I tried with cell2mat but I get an error because the sizes are different
thanks
Nikolas

 Réponse acceptée

Stephen23
Stephen23 le 4 Déc 2018
Modifié(e) : Stephen23 le 4 Déc 2018
Download padcat:
and use it like this:
>> M = padcat(A{:})
M =
0 0 0 0
1 1 NaN NaN
2 NaN NaN NaN

Plus de réponses (1)

[A{:}] % which is eqivalent to horzcat(A{:})

3 commentaires

thanks for the answer,
However, I don't want to have them all in the same row, but change them according to
the cell array. Imagine I have a cell array with 100 rows!
thanks
Nikolas
madhan ravi
madhan ravi le 4 Déc 2018
Modifié(e) : madhan ravi le 4 Déc 2018
just give an example of your desired output in the example you gave! plus how can you put them in an array when the number of columns are different??
well it's from a for loop that the results are saved in A by using
A{i,1)=...
So for the example above I would like to get
B=[0 0 0 0; 1 1 0 0 ; 2 0 0 0 ]
So actyally putting zeros where the elements are less

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by