"find" data range within vector and ensure second index greater than first
5 ビュー (過去 30 日間)
古いコメントを表示
I'm analyzing vehicle test data and trying to automatically identify the start and end indices to be analyzed. I'm using the "find" function and trying to utilize flexible thresholds to allow the analysis to work wth the broad range of data I expect to see. Unfortunately this also leaves the script prone to finding points where my end criteria occur before my start criteria.
%% Identify Start and End Data Points
% Identify start and end points to clip data to only that which needs to be
% analyzed.
for ff = 1:length(dataAll)
dataAll(ff).dataStart = find((dataAll(ff).Time > 0 & dataAll(ff).AccActPos > 20 & ...
dataAll(ff).GPSSpeed > 20 & abs(dataAll(ff).SteeringWheelAngle) > 60),1);
dataAll(ff).dataEnd = find((dataAll(ff).Time > 0 & dataAll(ff).GPSSpeed > 25 &...
dataAll(ff).AccActPos < 10 & abs(dataAll(ff).SteeringWheelAngle) < 50,1);
end
clearvars ff
This is the relevant portion of my existing script. It runs, but as noted it can find dataEnd with a lower index than dataStart and this doesn't work for the analysis. dataAll is the struct into which I'm loading data files, and there are always more than one. This is the need for the loop. I'm having a struggle day and can't find what I expect is an easy solution to add a criteria requiring dataEnd to be greater than dataStart. I know I can't simply add dataEnd > dataStart in the find definition for dataEnd since the field itself is yet undefined. I also know I can't create dataEnd and preload it with a value because it'll just evaluate whether or not that preloaded value is greater than dataStart.
If it helps to see something less complex and with data...
A = [0 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 2 1 0]
x = find(A>2,1);
y = find(A<3 & y>x,1);
I know this doesn't work because y>x can't be evaluated since y doesn't yet exist, but this is the net result I'm looking for. How do I force y > x? Is it effective or efficient to simply find all values of y = find(A<3) and then create z = find(y>x,1)?
0 件のコメント
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!