delete rows in a table
231 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jessica Blasco
el 24 de Mayo de 2018
Comentada: Jessica Blasco
el 24 de Mayo de 2018
Hi, I need help to delete several rows of a table whose column has a zeros for example
column 1 column2
1 2
3 2
4 0
5 6
1 0
9 0
I need delete the rows number 3,5 and 6
0 comentarios
Respuesta aceptada
Guillaume
el 24 de Mayo de 2018
Assuming you indeed have a matlab table:
yourtable(yourtable.column2 == 0, :) = [];
will delete all rows whose column2 is 0.
If your table is actually a matrix:
yourmatrix(yourmatrix(:, 2) == 0, :) = [];
will do the same.
Más respuestas (1)
Alfonso
el 24 de Mayo de 2018
Editada: Alfonso
el 24 de Mayo de 2018
Try this
% define your table
table_array = [1 2; 3 2; 4 0; 5 6; 1 0; 9 0];
% search index rows
[index_row index_col] = find(table_array==0);
% delete
table_array( index_row, : ) = [];
2 comentarios
Guillaume
el 24 de Mayo de 2018
Editada: Guillaume
el 24 de Mayo de 2018
Since you never use index_col, you can write:
[index_row, ~] = find(table_array == 0); %force the two output version of find.
A simpler version of the whole lot:
table_array(any(table_array == 0, 2), :) = [];
My understanding however is that the 0s are only in column 2
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!