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

110 ビュー (過去 30 日間)
ahmed obaid
ahmed obaid 2017 年 1 月 18 日
コメント済み: KAE 2019 年 10 月 17 日
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.
  1 件のコメント
KAE
KAE 2019 年 10 月 17 日
Wouldn't have know about this, so thanks. To remove empty columns which have no entries,
t = rmmissing(t,2);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by