In a large matrix, find and provide location of rows containing zeros
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Louise Wilson
il 22 Ago 2019
Commentato: David Hill
il 23 Ago 2019
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 Commenti
Risposta accettata
David Hill
il 22 Ago 2019
How about,
x=sum(Agoat(:,2:end),2);
Agoat(find(x==0),1);%answer matrix will contain all time stamps with zero rows.
3 Commenti
David Hill
il 23 Ago 2019
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!