how to remove variables of a table with a zeros in it
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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.)
채택된 답변
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))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!