Find value between the overall maximum and its following minimum
Show older comments
The command y = peak2peak(x) gives the value between the overall maximum max(y) and the overall minimum min(y).
In my case, 0,0052 and -0,0066 which equivalates to 0,0118.
I would need the value between the overall maximum and the immediate following minimum, 0,0052 and -0,0026 which equivalates to 0,0078.
Is there a command or work-around to return me the y-value of the minimum which follows the overall maximum?
Accepted Answer
More Answers (2)
Image Analyst
on 21 Nov 2021
To get the very next local min immediately following the max (at some particular index), I'd just "fall down" the signal until it turns around and heads upwards again
minIndex = maxIndex + 1; % Initialize search to start at the index right next to the max.
if maxIndex < length(y) - 1
while y(minIndex + 1) <= y(minIndex) && (minIndex + 1) < length(y)
minIndex = minIndex + 1;
end
end
Image Analyst
on 21 Nov 2021
If you have the Image Processing Toolbox you can use imregionalmax() and imregionalmin():
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 16;
y = rand(1, 25);
x = 1 : length(y);
plot(y, 'b.-', 'LineWidth',2, 'MarkerSize', 20)
grid on;
% Find local max
maxVector = imregionalmax(y)
xOfMaxes = x(maxVector)
yOfMaxes = y(maxVector)
% Plot max
hold on
plot(xOfMaxes, yOfMaxes, 'rv', 'LineWidth',2, 'MarkerSize',20);
% Find local min
minVector = imregionalmin(y)
xOfMins = x(minVector)
yOfMins = y(minVector)
% Plot min
hold on
plot(xOfMins, yOfMins, 'r^', 'LineWidth',2, 'MarkerSize',20);
% Say we want to find the y value of the first min after the third max.
% First get the index of where that min would be.
index = find(xOfMins > xOfMaxes(3), 1, 'first');
% Next get the y value there.
nextY = yOfMins(index)

Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!