Borrar filtros
Borrar filtros

Removing rows in matrix that contain zeros

2 visualizaciones (últimos 30 días)
Taylor Swaim
Taylor Swaim el 2 de Mayo de 2020
Comentada: Taylor Swaim el 2 de Mayo de 2020
Here is my code:
A = dmlread('B00001'.txt', '', 1,0)
for k=2:100;
A=A+dmlread(['B00',sprintf('%03d.txt',k)], '',1,0);
end
A=A/100
Right now it reads txt files B00001 to B00100, puts them in a matrix, and averages them to make a new matrix of the same size. But i need to remove the rows that contain zeros.

Respuesta aceptada

Image Analyst
Image Analyst el 2 de Mayo de 2020
Try this:
rowsWithZeros = any(A == 0, 2);
A = A(~rowsWithZeros, :);
  3 comentarios
Image Analyst
Image Analyst el 2 de Mayo de 2020
This seem to work fine:
A = randi([0, 9], 7, 10) % Sample data
rowsWithZeros = any(A == 0, 2);
A = A(~rowsWithZeros, :)
Taylor Swaim
Taylor Swaim el 2 de Mayo de 2020
Yes, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by