how extract table RowNames based on table elements
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all,
I have a table of only one colume with RowNames.
The table have numerical values and NaN.
I want to extract the RowNames of all of the NaN in the table. How can I do that?
Thanks in advance!
0 commentaires
Réponse acceptée
Voss
le 22 Fév 2023
% a table as you describe
t = table([1;NaN;3;4;NaN],'RowNames',{'A';'B';'C';'D';'E'})
% extract RowNames of the NaN rows
nan_rows = t.Properties.RowNames(isnan(t{:,:}))
0 commentaires
Plus de réponses (1)
Steven Lord
le 22 Fév 2023
I'd use ismissing, to avoid the need to extract the whole contents of the table into a separate array.
% a table as you describe
t = table([1;NaN;3;4;NaN],'RowNames',{'A';'B';'C';'D';'E'})
% extract RowNames of the NaN rows
nan_rows = t.Properties.RowNames(ismissing(t))
This also works if t has variables of different types. Yes, I could have listed "elderberry" but I need a missing value for the example.
t.FruitNames = ["apple"; "banana"; "cherry"; "date"; missing]
ismissing(t)
rowWithMissingNumberAndFruit = t.Properties.RowNames(all(ismissing(t), 2))
rowWithMissingNumberOrFruit = t.Properties.RowNames(any(ismissing(t), 2))
The approach Voss posted wouldn't work here.
isnan(t{:,:})
0 commentaires
Voir également
Catégories
En savoir plus sur Cell Arrays 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!