Effacer les filtres
Effacer les filtres

How to delect the zero values in table

34 vues (au cours des 30 derniers jours)
Chao Zhang
Chao Zhang le 24 Mai 2021
Commenté : Chao Zhang le 24 Mai 2021
There is a table in matlab, I want to know how to delete the entire row with zero values?
Many thanks in advance.

Réponse acceptée

the cyclist
the cyclist le 24 Mai 2021
If all of the table entries are numeric, then this will work:
% Create an example input table
x = [0; 1; 0; 2];
y = [0; 1; 0; 2];
z = [0; 0; 0; 0];
tbl = table(x,y,z)
tbl = 4×3 table
x y z _ _ _ 0 0 0 1 1 0 0 0 0 2 2 0
% Identify rows with all zeros, by first converting to numeric
rowsToDelete = all(table2array(tbl)==0,2);
% Delete the rows
tbl(rowsToDelete,:) = []
tbl = 2×3 table
x y z _ _ _ 1 1 0 2 2 0
  1 commentaire
Chao Zhang
Chao Zhang le 24 Mai 2021
Thanks, that makes sense

Connectez-vous pour commenter.

Plus de réponses (1)

Fangjun Jiang
Fangjun Jiang le 24 Mai 2021
Modifié(e) : Fangjun Jiang le 24 Mai 2021
a=[1 2 3;0 0 0 ; 1 0 2];
index=all(a==0,2);
a(index,:)=[];

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by