how to find the maximum length between few cell arrays

1 view (last 30 days)
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
Vicky
Vicky on 26 Apr 2012
Hi roberson,
clear all; clc;clf;
for k=1:5;
cos_el=R*cos(Elev);
asin_x=asin(cos_el);
cos_y=cos(asin_x);
vtec=stec.*(cos_y);
gistm =[ut, vtec];
TV_A{k}=ut;
L(k)=length(ut);
end
Following my coding. So i have 5 ut data and 5 vtec data.I need to find highest length of ut seems i have 5 ut data. then the highest length of ut data need to be in the first column in a new .mat form and following up by the other 5 vtec data. the 5 vtec data have to follow according the highest length of ut and seems the vtec data dimension are not same it must filled up with NaN or 0.
Jan
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.

Sign in to comment.

Answers (1)

Andrei Bobrov
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);

Tags

Community Treasure Hunt

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

Start Hunting!