Table, delete columns with zero

조회 수: 15 (최근 30일)
newbie9
newbie9 2019년 8월 27일
답변: Walter Roberson 2021년 7월 19일
I have a table with many rows and columns. How can I delete a column if any row contains zero? (I found a million ways to delete rows, but not columns, when dealing with tables.)

채택된 답변

newbie9
newbie9 2019년 8월 27일
편집: newbie9 2019년 8월 27일
Got it; it takes two steps. First repalce zeros with NaN, then can clean it up:
table2 = standardizeMissing(table1, 0); % the 0 is the value to be replaced with NaN
table2 = rmmissing(table2, 2); % the 2 is for deleting rows; use 1 to delete columns
  댓글 수: 1
seema rehman
seema rehman 2021년 7월 19일
It delete all columns if there is any zero

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 7월 19일
N = T.Properties.VariableNames;
nvar = length(N);
mask = true(1,nvar);
for K = 1 : nvar
if isnumeric(T.(N{K})) && any(T.(N{K}) == 0, 'all')
mask(K) = false;
end
end
newT = T(:,mask);

카테고리

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