Finding a minimum in a data set after certain value or in a specified range
古いコメントを表示
Dear All
I have a dataset of time versus pressure, and I want to find the minimum pressure and its index after some time t1.
Once that is done, I would like to find the index of a given pressure; after the minimum pressure above.

For example, in the image below x-axis is time and y-axis is pressure. First I want to find the minimum pressure after time = 5000 along with its index. Then once that is found I want to find the index of pressure = 99 after the above mentioned minimum pressure.
Please need your help.
回答 (2 件)
Walter Roberson
2017 年 2 月 20 日
start_point = 5000;
special_target = 99;
locs_in_range = find(t > start_point);
selected_y = y(locs_in_range);
[min_pressure, relidx] = min(selected_y);
idx_at_min_pressure = locs_in_range(relidx);
locs_in_range = locs_in_range(relidx+1:end);
selected_y = selected_y(relidx+1:end);
[~, relidx] = min( abs(selected_y - special_target) );
idx_at_special_target = locs_in_range(relidx);
Your requested outputs are min_pressure, idx_at_min_pressure and idx_at_special_target
Note: I do not assume that there will be a value that is exactly 99; instead I search for the value closest to 99. It appears plausible that your range of values goes below 99 and then above 99 again, possibly several times (we cannot tell if that is a bunch of points close together or just line drawn thickly.) The point that is closest to 99 might be towards the right rather than towards the left. Even if there is a value that is exactly 99, it might not be on the left side. (This is the kind of thing that happens when you specify locating a specific target in floating point numbers, instead of asking for "the first place that is at or below the target")
Image Analyst
2017 年 2 月 20 日
Try this (untested because you forgot to include your data):
% First find out what index x (time) exceeds 5000:
tIndex = find(x >= 5000, 1, 'first')
% Make a copy of pressure so as to not mess up original pressure array.
y = pressure;
% Set y up to that index to infinity, to make sure we don't find any y in that x range.
y(1 : tIndex) = inf;
% Find differences between the y and our desired value of 99
diffs = abs(y - 99);
% Find out which index has the closest y value to 99.
[minDiff, indexOfMinDiff] = min(diffs);
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!