In a large matrix, find and provide location of rows containing zeros

조회 수: 10 (최근 30일)
I have a series of large matrix, 7184x72001, in which the first column is a datenum vector, and all the rows represent values for each datenum.
If a row didn't meet certain criteria, I asked my forloop to fill it with zeros. Unfortunately I didn't consider how large my matrix was and how hard it would then be to find the rows that contain zeros, if they exist. I know that in my first example, there is one row that is all zeros, excluding the datenum vector in the first column.
Is it possible to make a variable which contains the datenum value for the rows which contain zeros?
The following code, I have used to confirm that the row of zeros exist, but it doesn't tell me WHERE it is. Ideally I would get a list of datenums for the rows which are filled with zeros.
for row = 1 : size(Agoat, 1)
zeroLocations{row} = find(Agoat(row, :) == 0)
end
Thank you everyone!
  댓글 수: 2
Ted Shultz
Ted Shultz 2019년 8월 22일
Are you only trying to find rows where every value in the row is 0?
Louise Wilson
Louise Wilson 2019년 8월 22일
Hi Ted, thanks for response! The first column in every row has a datenumber, so I am trying to find where row 2:n(rows) will be 0. And then, get the value in the first column for that row. Does it make sense?

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

채택된 답변

David Hill
David Hill 2019년 8월 22일
How about,
x=sum(Agoat(:,2:end),2);
Agoat(find(x==0),1);%answer matrix will contain all time stamps with zero rows.
  댓글 수: 3
Louise Wilson
Louise Wilson 2019년 8월 23일
I get that the first line creates a vector containing the sum of each row.
What exactly is the second line doing-looking for values in that which are zero? Where does it create the new vector with the datenum values?
David Hill
David Hill 2019년 8월 23일
If finds the indexes of the zero rows from the column vector x and indexes into the Agoat matrix at those indexes along the first time-stamp column to produce the datenum values of the zero rows as a column vector.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by