Want to get the Highest maxima and Lowest minima form all local maxima and minima.

Illustration
ehtishamr96 - 2024-06-07T15:08:04+00:00
Question: Want to get the Highest maxima and Lowest minima form all local maxima and minima.

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

Expert Answer

Profile picture of Kshitij Singh 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:

  1. Identify Local Maxima and Minima:

  2. Extract Values:

    • Once you have the logical arrays, you can extract the corresponding values from your data array.
    • For example, if your data is stored in a vector A, you can use indexing to get the values of local minima and maxima.
  3. Highest Maxima and Lowest Minima:

    • To find the highest maxima, select the maximum value among the local maxima.
    • To find the lowest minima, select the minimum value among the local 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. 

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!