How do we eliminated (empty or zeros) Columns or Rows from tables in Matlab
110 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ahmed obaid
el 18 de En. de 2017
Comentada: KAE
el 17 de Oct. de 2019
Dear all
i have read tables using matlab, in my dataset some existed rows and columns are fully empty or contain zero's values, how do we can eliminated these columns or rows from tables , thanks for any suggestion
0 comentarios
Respuesta aceptada
dpb
el 18 de En. de 2017
To eliminate columns fully containing NaN in table t, use
t(:,all(ismissing(t)))=[];
Similar logic for zero values; be careful what you eliminate looks like you could get down to having very little left, perhaps...
Más respuestas (1)
Peter Perkins
el 19 de En. de 2017
Also beginning in R2016b, use rmmissing:
>> t = array2table(randn(5));
>> t{3,:} = NaN;
>> t.Var3(:) = NaN
t =
Var1 Var2 Var3 Var4 Var5
________ ________ ____ ________ _________
-0.45706 1.0022 NaN -0.84257 0.72003
0.089446 0.92481 NaN 0.37592 -0.99347
NaN NaN NaN NaN NaN
0.18133 -0.64009 NaN 0.82489 -0.27627
-0.59695 -0.44802 NaN -0.21385 -0.072641
>> t = rmmissing(t,1,'MinNumMissing',5)
t =
Var1 Var2 Var3 Var4 Var5
________ ________ ____ ________ _________
-0.45706 1.0022 NaN -0.84257 0.72003
0.089446 0.92481 NaN 0.37592 -0.99347
0.18133 -0.64009 NaN 0.82489 -0.27627
-0.59695 -0.44802 NaN -0.21385 -0.072641
>> t = rmmissing(t,2,'MinNumMissing',4)
t =
Var1 Var2 Var4 Var5
________ ________ ________ _________
-0.45706 1.0022 -0.84257 0.72003
0.089446 0.92481 0.37592 -0.99347
0.18133 -0.64009 0.82489 -0.27627
-0.59695 -0.44802 -0.21385 -0.072641
I don't see any row or variable in your example table that is all zeros. If you want to remove such rows, you might use standardizeMissing before calling rmmissing, or you might call ismissing with 0 specified as the misisng data indicator.
1 comentario
KAE
el 17 de Oct. de 2019
Wouldn't have know about this, so thanks. To remove empty columns which have no entries,
t = rmmissing(t,2);
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!