필터 지우기
필터 지우기

Removing rows in matrix that contain zeros

조회 수: 2 (최근 30일)
Taylor Swaim
Taylor Swaim 2020년 5월 2일
댓글: Taylor Swaim 2020년 5월 2일
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.

채택된 답변

Image Analyst
Image Analyst 2020년 5월 2일
Try this:
rowsWithZeros = any(A == 0, 2);
A = A(~rowsWithZeros, :);
  댓글 수: 3
Image Analyst
Image Analyst 2020년 5월 2일
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 2020년 5월 2일
Yes, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by