Count number of times values in vector A are greater than corresponding values in vector B
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ulrik Nash
am 27 Jun. 2011
Kommentiert: Martin Adams
am 19 Okt. 2018
Hi Everyone,
Suppose I have two one-column vectors of equal column height, A and B.
For example
A = [1;2;3]
and
B = [2;0;4]
What statement will allow me to count the number of times values in vector A are greater than corresponding values in vector B. In this case, the answer is 1, because only 2 in A is greater than its corresponding value in B, namely 0.
Regards,
Ulrik.
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 27 Jun. 2011
n = sum(A>B);
1 Kommentar
Martin Adams
am 19 Okt. 2018
Works great - and a simple solution too.
I used this to drastically speed up my for loop in which I was doing a logic test.
To speed up the process, I added values of the test to be a value inside of the matrix and then counted how many matrix entries were greater than 0.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!