필터 지우기
필터 지우기

Find minimum or maximum value - two conditions

조회 수: 4 (최근 30일)
LukeJes
LukeJes 2023년 5월 9일
댓글: LukeJes 2023년 5월 10일
Hi there,
I have a problem where I am trying to find the index of minimum or maximum values based on two conditions. I have separated my data into 10 second blocks, with 1 data point per second. The two conditions are as follows:
1) the next minimum value must not be within 5 seconds of the previous minimum value
2) the next minimum value must be within the 10 second block following the previous minimum value's 10 second block.
Presently, I can ensure the next indexed minimum value meets one condition or the other, but I cannot ensure that it meets both.
Any ideas would be much appreciated!
Luke
  댓글 수: 3
LukeJes
LukeJes 2023년 5월 9일
편집: LukeJes 2023년 5월 9일
Please see attached.
I've included my code below, up until where I am having the problem.
My expected result would be a minimum value from each 10 second block (odds:evens) that are each not within 5 seconds of their previous minimum value. Ideally it'd be a find function with two conditions, such as find(min(data(idxmcamin(j-1)+5:evens(j),2)) && min(data(odds(j-1):evens(j),2)). I hope this makes sense!
clear
spreadsheets = dir('*.xlsx');
spreadsheets = {spreadsheets.name};
for i = 1:length(spreadsheets)
trial = spreadsheets(i);
trial = char(trial);
data = xlsread(trial);
evens = 0:10:length(data);
evens = evens(1,2:end);
odds = 1:10:length(data);
odds = odds(1,2:end);
mcaoutliers = isoutlier(data(:,2));
mapoutliers = isoutlier(data(:,3));
if sum(mcaoutliers)>0
data(:,2) = filloutliers(data(:,2),"linear");
elseif sum(mapoutliers)>0
data(:,3) = filloutliers(data(:,3),"linear");
else
%
end
% find max and min and time
for j = 1:length(evens)
[idxevens,~] = find(data(:,1)==evens(j));
if j == 1
% mca
valmcamin(j) = min(data(2:idxevens,2));
valmcamax(j) = max(data(2:idxevens,2));
[idxmcamin(j),~] = find(data(:,2)==valmcamin(j),1,'first');
[idxmcamax(j),~] = find(data(:,2)==valmcamax(j),1,'first');
timemcamin(j) = data(idxmcamin,1);
timemcamax(j) = data(idxmcamax,1);
% map
valmapmin(j) = min(data(2:idxevens,3));
valmapmax(j) = max(data(2:idxevens,3));
[idxmapmin(j),~] = find(data(:,3)==valmapmin(j),1,'first');
[idxmapmax(j),~] = find(data(:,3)==valmapmax(j),1,'first');
timemapmin(j) = data(idxmapmin,1);
timemapmax(j) = data(idxmapmax,1);
else
% mca
valmcamin(j) = min(data(idxmcamin(j-1)+5:evens(j),2)); % PROBLEM
valmcamax(j) = max(data(idxmcamax(j-1)+5:evens(j),2)); % PROBLEM
[idxmcamin(j),~] = find(data(:,2)==valmcamin(j),1,'first');
[idxmcamax(j),~] = find(data(:,2)==valmcamax(j),1,'first');
timemcamin(j) = data(idxmcamin(j),1);
timemcamax(j) = data(idxmcamax(j),1);
LukeJes
LukeJes 2023년 5월 10일
Please let me know if you require any other information to help with answering this question :)

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2023년 5월 9일
I think the islocalmin and islocalmax functions will be of use to you. See the MinSeparation name-value argument.
  댓글 수: 2
LukeJes
LukeJes 2023년 5월 9일
편집: LukeJes 2023년 5월 9일
Hi Steven,
Thanks for the suggestion. Unfortunately islocalmin with the MinSeparation argument is a bit off in places. I've attached my data and code above to give you more idea of what I'm working with :)
LukeJes
LukeJes 2023년 5월 10일
Please let me know if you require any other information to help with answering this question :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by