Identify when a exceedance occurs and return the start point and length of each exceedance
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Voss
on 20 Jun 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
start_idx = strfind([false,idx],[false,true])
end_idx = strfind([idx,false],[true,false])
Array1 = start_idx(:);
Array2 = end_idx(:)-start_idx(:)+1;
disp(Array1)
disp(Array2)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!