how to find the maximum length between few cell arrays
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 26 de Abr. de 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.
Respuestas (1)
Andrei Bobrov
el 26 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!