how to make the vectors length in the cell array equal

hi all, I've a cell array which contains vectors with different length.I want to make the vectors length with maximum length of vector.how to do that.Pls help...

2 Comments

If length is less, you have to add elements. It depends on what elements you want to add? zero's? NaN's? or what numbers?
thank u for ur reply. The vectors i've mentioned is a features, i.e 8 chain code of digits 0 to 9. If i add zero's, is it possible that the characteristic of the feature will be change?

Sign in to comment.

 Accepted Answer

example:
Let A - your cell array
A = arrayfun(@(x)randi(45,randi([3 8]),1),1:10,'un',0);
n = cellfun(@numel,A);
m = max(n);
out = cellfun(@(x,y)[x(:);zeros(max(n)-y,1)],A,num2cell(n),'un',0);

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!