Find the longest array in an array of vectors
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
skrowten_hermit
le 9 Oct 2020
Commenté : Ameer Hamza
le 9 Oct 2020
I have 5 vectors y1, y2, y3, y4, y5 of variable number of samples or values. I have created a cell array as:
vectorarray = {y1, y2, y3, y4, y5}
I know the classic way of finding the largest number of samples in the elements of the cell array can be done as follows:
maxsamples = 0
for k = 1:numel(vectorarray)
currveclength = length(vectorarray{k})
if currveclength > maxsamples
maxsamples = currveclength
end
end
Is there a simpler way to do it in a single line in Matlab?
0 commentaires
Réponse acceptée
Ameer Hamza
le 9 Oct 2020
Modifié(e) : Ameer Hamza
le 9 Oct 2020
[max_val, idx] = max(cellfun(@numel, vectorarray))
2 commentaires
Plus de réponses (0)
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!