Finding largest data from table
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sebastian Daneli
le 15 Nov 2021
Modifié(e) : Seth Furman
le 16 Nov 2021
Lets say that I have a table containing three matricies of different lengths.
X1=[9 6 9 0;3 2 7 0];
X2=[0 2;4 0];
X3=[3 1 2; 8 9 7];
X=table(X1,X2,X3)
How can i I find the longest one? Is there a way to find more then one matrix of a specific lenght? Lets say the ones that are the longest.
1 commentaire
Réponse acceptée
Chunru
le 15 Nov 2021
Modifié(e) : Chunru
le 15 Nov 2021
X1=[9 6 9 0;3 2 7 0];
X2=[0 2;4 0];
X3=[3 1 2; 8 9 7];
X4 = X1;
X=table(X1,X2,X3,X4)
len = table2array(varfun(@(x) size(x, 2), X));
% max will find 1 entry only
[lmax, idx] = max(len)
% if you want multiple entries
idxall = find(len == lmax)
2 commentaires
Seth Furman
le 16 Nov 2021
Modifié(e) : Seth Furman
le 16 Nov 2021
The only thing I would add is that
@(x) size(x, 2)
can be replaced with
@width
since the width function returns the number of variables in a table or the number of columns in an array.
e.g.
X1 = [9 6 9 0;3 2 7 0];
X2 = [0 2;4 0];
X3 = [3 1 2; 8 9 7];
X4 = X1;
X = table(X1,X2,X3,X4)
varfun(@width, X, "OutputFormat", "uniform")
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables 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!