Identify when a exceedance occurs and return the start point and length of each exceedance
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Voss
2024-6-20
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!