Want to get the Highest maxima and Lowest minima form all local maxima and minima. I am using the Islocal maxima and minima function but still not getting the required result. i shared the snippet of code below Phase C function [Rpeak_C ,Rss_C ,Tpeak_C, Ratio_Rpeak_C_Rss_C, Delta_C, L_C] = calculate_phase_C(t, Active_Receptor_concentration, T_startC) % Extract active receptor concentration within Phase C time range PhaseC_indices = (t > T_startC); PhaseC_time = t(PhaseC_indices); % Define the PhaseC_time based on the indices PhaseC_concentration = Active_Receptor_concentration(PhaseC_indices); % Find local maxima within Phase C time range max_indices = find(islocalmax(PhaseC_concentration)); % Find local minima within Phase C time range min_indices = find(islocalmin(PhaseC_concentration)); % Check the local maxima and finds the highest maxima in all if ~isempty(max_indices) && ~isempty(min_indices) % Find the highest local maximum [Rpeak_C, maxIdx] = max(PhaseC_concentration(max_indices)); % Get the corresponding time for the highest local maximum Tpeak_C = PhaseC_time(max_indices(maxIdx)); % Assign 'High' as the type of peak Rpeak_C_type = 'High'; % Check the local minima and finds the lowst minima in all elseif ~isempty(min_indices) [Rpeak_C, minIdx] = min(PhaseC_concentration(min_indices)); Tpeak_C = PhaseC_time(min_indices(minIdx)); Rpeak_C_type = 'Low'; % If neither local maxima nor local minima exist else Rpeak_C = NaN; Rpeak_C_type = 'None'; Tpeak_C = NaN; end
Kshitij Singh answered .
2025-11-20
Certainly! To find the highest maxima and lowest minima from all local maxima and minima in MATLAB, you can follow these steps:
Identify Local Maxima and Minima:
islocalmin and islocalmax functions to detect local minima and maxima in your data1.1 (true) for detected local minima or maxima.Extract Values:
A, you can use indexing to get the values of local minima and maxima.Highest Maxima and Lowest Minima:
Here’s a brief example using MATLAB:
% Example data (replace with your actual data)
A = [10, 5, 8, 3, 12, 7, 15, 4];
% Detect local minima and maxima
TF_min = islocalmin(A);
TF_max = islocalmax(A);
% Extract values
local_minima = A(TF_min);
local_maxima = A(TF_max);
% Highest maxima and lowest minima
highest_maxima = max(local_maxima);
lowest_minima = min(local_minima);
disp(['Highest Maxima: ', num2str(highest_maxima)]);
disp(['Lowest Minima: ', num2str(lowest_minima)]);
Remember to replace the example data (A) with your actual dataset. This code snippet will give you the highest maxima and lowest minima from your local extrema.