How do I select values bigger than a certain value & at least 4?
Ältere Kommentare anzeigen
Hi there,
I need to find a way to make a matlab command for the following: I have an array with 2500x1 doubles. And I need to find the doubles that are at least 150 and when there are more than 4 values >150 next to each other.
For example [125 165 150 124 126 154 103 99 160 198 *140] should return [0 0 0 0 0 0 0 0 0 0 0] and [149 *156 158 159 168 *149 120 *150 160 140 125] should return [0 1 1 1 1 0 0 0 0 0 0]
I have the following: x = array > 150 & ????
I don't know how to do the at least 4 following values in a simple way, I can only think of an if loop...
Does anyone know if there is a command for that?
Thanks in advance!
Akzeptierte Antwort
Weitere Antworten (2)
the cyclist
am 9 Jan. 2017
VALUE_THRESHOLD = 150;
RUN_THRESHOLD = 4;
x = [149 156 158 159 168 149 120 150 160 140 125];
above = (x >= VALUE_THRESHOLD);
[b,n,bi] = RunLength(above);
meetsCriteria = b & n >= RUN_THRESHOLD;
start = bi(meetsCriteria);
run = n(meetsCriteria);
out = zeros(size(x));
for nr = 1:numel(run)
out(start(nr):start(nr)+run(nr)-1) = 1;
end
1 Kommentar
the cyclist
am 9 Jan. 2017
Bearbeitet: the cyclist
am 9 Jan. 2017
Note: It was not clear to me how to handle value exactly equal to 150, so you may need to adjust accordingly.
Roger Stafford
am 9 Jan. 2017
Let A be your 2500 by 1 row vector.
f = find(diff([false;A>150;false]));
f1 = f(1:2:end-1);
ix = f1(find(f(2:2:end)-f1>4));
The vector ix will have indices pointing to the first elements of A for series of more than four consecutive elements greater than 150.
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!