how to find the maximum length between few cell arrays
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Jan
le 26 Avr 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.
Réponses (1)
Andrei Bobrov
le 26 Avr 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 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!