How can I count the number of times the value of an array/vector/matrix changes value from x to y?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ahoora Saadat
am 21 Mär. 2017
Kommentiert: Ahoora Saadat
am 22 Mär. 2017
For example
Let A = [1;2;1;1;1;3;5;5;5;1;1;1;6;3;4;2;8;6;6;6;6]
How can I determine the number of times the value goes from say 2 to 1, or from 6 to 3 or from 1 to 1 etc. ?
Thank you.
0 Kommentare
Akzeptierte Antwort
Thorsten
am 21 Mär. 2017
firstvalue = 2;
nextvalue = 1;
A = A(:); % convert matrix to vector
N = nnz(A(1:end - 1) == firstvalue & A(2:end) == nextvalue);
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!