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

110 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2017-1-18
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...

更多回答(1 个)

Peter Perkins
Peter Perkins 2017-1-19
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.

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by