MATLAB: How to make each cell array consistent in length

digital image processingimage analysisimage processing

In a cell array each element is 1Xlength. This length is not equal. I want to get the maximum length and then want to make each cell with same length by padding zeros in it.

Best Answer

A final attempt to answer this question :-)
C = {1:4 1:2 ; 1:5 1:6 ; 1 1:3} % a m-by-n cell array
N = cellfun(@numel, C) % old lengths of cell elements
M = 3 ; % new length should be multiple of M
newN = M * ceil(N / M) % new lengths of cell elements
padfun = @(k) [C{k} zeros(1, newN(k) - N(k))] ;
C2 = arrayfun(padfun, 1:numel(C) , 'un', 0) ; % apply padding to all elements of C
C2 = reshape(C2, size(C)) % reshape (if needed)