How do we eliminated (empty or zeros) Columns or Rows from tables in Matlab

119 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

dpb
dpb il 18 Gen 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...

Più risposte (1)

Peter Perkins
Peter Perkins il 19 Gen 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.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by