how to find the maximum length between few cell arrays
1 view (last 30 days)
Show older comments
Hi there, I dont know how to find the maximum length between few cell arrays and once the maximum cell array is detected, the value in the detected cell array have to enter into new column.
3 Comments
Jan
on 26 Apr 2012
Neither "matlab" nor "matlab code" are meaningful tags in a Matlab forum. Of course all question concern Matlab. The tags are used to classify questions, therefore meaningful tags help to improve the forum.
The magic frequently appearing cleanup "clear all; clc; clf;" is brute. Most likely "clear variables" is wanted, but it is a good programming practize to avoid such brute cleaning. It's like burning down the house instead of locking the door, when you leave.
Answers (1)
Andrei Bobrov
on 26 Apr 2012
Let Ut - cell array 1 x 5 , contains column vectors with size n(k) x 1, for k = 1:5.
Vtec - cell array 1 x 5, contains vector m x 1, here all m <= max(n).
e.g. data:
Ut = arrayfun(@(ii)ii*ones(randi(10),1),1:5,'un',0);
Vtec = arrayfun(@(ii)ii*ones(randi(6),1),1:5,'un',0);
% solution
n = max(cellfun('length',Ut));
out = cellfun(@(x)[x;nan(n-numel(x),1)],Vtec,'un',0);
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!