Azzera filtri
Azzera filtri

Identify when a exceedance occurs and return the start point and length of each exceedance

1 visualizzazione (ultimi 30 giorni)
I have two large arrays with magnetic heading values:
hdg1=[10;10;10;10;10;10;10;10;10;10;10;10]; %actual data is thousands of values.
hdg2=[12;18;18;18;13;14;10;20;20;12;13;12];
calculate delta between each item.
hdgdelta = abs(hdg1 - hdg2);
Need help with:
Identifying when and how long hdgdelta values are greater than say 6.
I would like to see the results returned as such:
Array1: The starting points/rows where hdgdelta exceedance groups exceed the value of 6. (Rows 2 and 8 in this case).
Array2: The duration of those splits. i.e The duration/count for when subsequent rows have a value greater than 6. Ie. 2,3,4, (length of 3) and 8,9 (length of 2)
The example result that I would like to see:
Array1 = [2;8]; %starting points/rows where exceedance happen
Array2 = [3;2]; %duration (in # of rows) for each exceedance.

Risposte (1)

Voss
Voss il 20 Giu 2024
One way is to use strfind to find the starts and ends of the sections where hdgdelta>=6:
hdg1=[10;10;10;10;10;10;10;10;10;10;10;10]; %actual data is thousands of values.
hdg2=[12;18;18;18;13;14;10;20;20;12;13;12];
hdgdelta = abs(hdg1 - hdg2);
idx = hdgdelta(:).' >= 6
idx = 1x12 logical array
0 1 1 1 0 0 0 1 1 0 0 0
start_idx = strfind([false,idx],[false,true])
start_idx = 1x2
2 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
end_idx = strfind([idx,false],[true,false])
end_idx = 1x2
4 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Array1 = start_idx(:);
Array2 = end_idx(:)-start_idx(:)+1;
disp(Array1)
2 8
disp(Array2)
3 2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by