How can I equalize the size of all arrays in a cell array?

This is my cell array:
Q_Vic1 =
[29x1 double] [28x1 double] [28x1 double] [28x1 double] [28x1 double] [28x1 double] [28x1 double] [28x1 double] [28x1 double] [28x1 double] [29x1 double]
I need to equalize all arrays to size of [29x1]-max array size.
I tried this code(found from Matlab Answers,the one suggested by Laura Proctor ):
I get same length but different size!:
Q_Vic1 =
[29x1 double] [1x29 double] [1x29 double] [1x29 double] [1x29 double] [1x29 double] [1x29 double] [1x29 double] [1x29 double] [1x29 double] [29x1 double]
I tried the same kind of code with size and cellfun and its still not working.I know in order to convert the cell to matrix the arrays must be of same size. Any suggestions?I would really appreciate general purpose codes,rather than taking transpose of the specific arrays:I would be using the same code for different signals(inputs). Ultimately,I need to store all the arrays in different matrices(arrays,not in cell) and process these signals further. It is difficult to access them(the array) when they are in a cell. If there is an alternate method of storing the arrays in individual normal arrays,I would welcome that too.

댓글 수: 5

simply change < to <= in the original answer
I didn't understand your comment.Could you please elaborate?
Study this
Q = { [1:10]',[1:12]',[1:5]'}
len = max( cellfun(@length, Q ) )
Q2 = cellfun( @(v) padarray(v,[len-length(v),0],nan,'post'), Q, 'uni',false )
which outputs
Q =
[10x1 double] [12x1 double] [5x1 double]
len =
12
Q2 =
[12x1 double] [12x1 double] [12x1 double]
>>
padarray is a function in the Image Toolbox
Thank you! I got it, finally.
Thank a lot. It works very well!!!!!

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

 채택된 답변

Jos (10584)
Jos (10584) 2017년 12월 1일
편집: Jos (10584) 2017년 12월 1일
You want to pad the shorter arrays with zeros?
Q_Vic1 = {[1 2 3], [1 2], [1 2 3 4]}
ML = max(cellfun(@numel, Q_Vic1))
Q_Vic1_out = cellfun(@(x) [x zeros(1, ML - numel(x))], Q_Vic1, 'un', 0)

댓글 수: 2

I used it and it showed: error: horizontal dimensions mismatch (2998x1 vs 1x1).
I have cell array I need them in the same lenght:
[2998x1 cell] [2998x1 cell]
[3214x1 cell] [3214x1 cell]
[2997x1 cell] [2997x1 cell]
[3214x1 cell] [3214x1 cell]
[2998x1 cell] [2998x1 cell]
[3216x1 cell] [3216x1 cell]

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

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by