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

조회 수: 3 (최근 30일)
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

채택된 답변

Stephen23
Stephen23 2018년 12월 4일
편집: Stephen23 2018년 12월 4일
Download padcat:
and use it like this:
>> M = padcat(A{:})
M =
0 0 0 0
1 1 NaN NaN
2 NaN NaN NaN

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 12월 4일
[A{:}] % which is eqivalent to horzcat(A{:})
  댓글 수: 3
madhan ravi
madhan ravi 2018년 12월 4일
편집: madhan ravi 2018년 12월 4일
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??
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018년 12월 4일
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

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

카테고리

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