How do we eliminated (empty or zeros) Columns or Rows from tables in Matlab
119 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all
i have read tables using matlab, in my dataset some existed rows and columns are fully empty or contain zero's values, how do we can eliminated these columns or rows from tables , thanks for any suggestion
0 commentaires
Réponse acceptée
dpb
le 18 Jan 2017
To eliminate columns fully containing NaN in table t, use
t(:,all(ismissing(t)))=[];
Similar logic for zero values; be careful what you eliminate looks like you could get down to having very little left, perhaps...
Plus de réponses (1)
Peter Perkins
le 19 Jan 2017
Also beginning in R2016b, use rmmissing:
>> t = array2table(randn(5));
>> t{3,:} = NaN;
>> t.Var3(:) = NaN
t =
Var1 Var2 Var3 Var4 Var5
________ ________ ____ ________ _________
-0.45706 1.0022 NaN -0.84257 0.72003
0.089446 0.92481 NaN 0.37592 -0.99347
NaN NaN NaN NaN NaN
0.18133 -0.64009 NaN 0.82489 -0.27627
-0.59695 -0.44802 NaN -0.21385 -0.072641
>> t = rmmissing(t,1,'MinNumMissing',5)
t =
Var1 Var2 Var3 Var4 Var5
________ ________ ____ ________ _________
-0.45706 1.0022 NaN -0.84257 0.72003
0.089446 0.92481 NaN 0.37592 -0.99347
0.18133 -0.64009 NaN 0.82489 -0.27627
-0.59695 -0.44802 NaN -0.21385 -0.072641
>> t = rmmissing(t,2,'MinNumMissing',4)
t =
Var1 Var2 Var4 Var5
________ ________ ________ _________
-0.45706 1.0022 -0.84257 0.72003
0.089446 0.92481 0.37592 -0.99347
0.18133 -0.64009 0.82489 -0.27627
-0.59695 -0.44802 -0.21385 -0.072641
I don't see any row or variable in your example table that is all zeros. If you want to remove such rows, you might use standardizeMissing before calling rmmissing, or you might call ismissing with 0 specified as the misisng data indicator.
1 commentaire
KAE
le 17 Oct 2019
Wouldn't have know about this, so thanks. To remove empty columns which have no entries,
t = rmmissing(t,2);
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!