フィルターのクリア

how to remove variables of a table with a zeros in it

4 ビュー (過去 30 日間)
priyam kar
priyam kar 2024 年 5 月 26 日
コメント済み: priyam kar 2024 年 5 月 27 日
I have a table where few variables contain zeros as well as non zero values in it. I want to remove the variables with even a single zero in it. can anyone help me with that?
  2 件のコメント
the cyclist
the cyclist 2024 年 5 月 26 日
I realized that there is a nuance here, that I did not consider in my solution.
Is there any chance that any of your variables are logical (i.e. true/false)? If so, do you want to remove that variable if "false" appears? (Both my and @Matt J's solutions will remove a column with "false" in it.)
priyam kar
priyam kar 2024 年 5 月 27 日
The table conatains only numeric values and your solution woked perfectly. Thank you very much.

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

採用された回答

the cyclist
the cyclist 2024 年 5 月 26 日
% Example data
x = ["a";"b";"c"];
y = [4;5;6];
z = [0;7;8];
tbl = table(x,y,z);
% Find variables with a zero
hasZero = any(ismissing(tbl,0));
% Make a new table without those variables
tbl2 = tbl(:,not(hasZero))
tbl2 = 3x2 table
x y ___ _ "a" 4 "b" 5 "c" 6

その他の回答 (1 件)

Matt J
Matt J 2024 年 5 月 26 日
編集済み: Matt J 2024 年 5 月 26 日
keep=all(yourTable{:,:},1);
yourTable=yourTable(:,keep);
  1 件のコメント
priyam kar
priyam kar 2024 年 5 月 27 日
Thank you so much, it works fine

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by