number of values greater than zero in a large matrix
Ältere Kommentare anzeigen
I have a 900X25 matrix The matrix has rows of zeros with one or two numeric values. Some rows have all zeros. What I want to do is have Matlab go through each row of zeros and find the lowest numeric value in that row, or if there is all zeros in that row, then the code will just skip that row. I want the code to return a 1X25 or a 25X1 array which will let me know the number of times there was a numeric value in each column. And not counting the larger numbers if there were more than one number in a given row. Example of data:
Grandmatrix = 23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 87 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 93 12 0 0 0 0 0 0 0 0 0 0 0 0 0
Reducedmatrix = 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0
4 Kommentare
Sean de Wolski
am 18 Jun. 2012
Are you missing a one where the 12 is in Reducedmatrix?
If so:
any(x>0)
will give the result you want
charles atlas
am 18 Jun. 2012
Sean de Wolski
am 18 Jun. 2012
Andrei and I are clearly missing the point. ZCould you give us a small example (3x3 maybe) and explain.
charles atlas
am 18 Jun. 2012
Antworten (3)
Andrei Bobrov
am 18 Jun. 2012
Reducedmatrix = any(Grandmatrix);
or?
Reducedmatrix = sum(Grandmatrix~=0);
charles atlas
am 18 Jun. 2012
0 Stimmen
Walter Roberson
am 18 Jun. 2012
sum(GrandMatrix == repmat( min(GrandMatrix,2), 1, size(GrandMatrix,2) ))
2 Kommentare
charles atlas
am 19 Jun. 2012
Walter Roberson
am 19 Jun. 2012
Dang, I keep forgetting about the other argument to min()
sum(GrandMatrix == repmat( min(GrandMatrix,[],2), 1, size(GrandMatrix,2) ))
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!