Table, delete columns with zero
Afficher commentaires plus anciens
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.)
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 19 Juil 2021
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);
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!