Define time interval for wave of highest peak

3 views (last 30 days)
Along with greeting, I attach 2 .txt files, one for amplitudes and the other for flow, which are 1441x50, where each column represents different simulations and the rows are the variation of the parameter (both amplitude and flow) as a function of time (for that I define a time vector). The problem I have is how to define both for the case of amplitude and flow, the time interval (x axis), where the maximum peak is found but considering the entire wave of said peak, and unfortunately all the scenarios are very different, then I wanted to ask for help to define some criteria or method to get the time range.
I present two figures that show in a schematic way what I need (I did it visually by seeing the maximum peak and defined the interval by seeing the wave that contained it), but I need it in numerical form, I mean to quantify that interval, and define a criterion to be able to perform it for all simulations, in total there are 50 simulations.
In red vertical lines I defined an interval considering the wave where the peak value is, but it was done by eye, so I need your help to be able to do it automatically with matlab and defining a criterion to be able to do it, since as I mentioned earlier the simulations are very different.
Thanks greetings.
close all, clear all, clc
load 'flow.txt' % amplitude vector is defined in meters
load 'amplitude.txt' % the flow vector is defined in (m^3/s)
t=(0:10:4*3600)'; % is a time vector every 10 seconds in a total of 4 hours
figure, plot(t,amplitude(:,1)) , ylabel('Amplitude (m)') , xlabel('Time (s)')
figure, plot(t,flow(:,1)) , ylabel('Flow (m^3/s)') , xlabel('Time (s)')

Answers (1)

KSSV
KSSV on 15 Jun 2021
Use the function max, it will give maximum value along with the index of the maximum value; using this index you can get the respective time.
[max_val,idx] = max(A(:,1)) ;
t_max = t(idx) ;
[t_max max_val]
  2 Comments
ignacio bobadilla tapia
ignacio bobadilla tapia on 15 Jun 2021
@KSSV I need to do it for the 50 simulations, all these sinusoidal curves being very different, so I need to program a code that does it automatically, and I calculate the time difference where the wave of the maximum peak begins and ends. Estimated could you understand me?
KSSV
KSSV on 15 Jun 2021
You can run a loop for each column. Also max works on matrix, it gives max value and respective indices for a given input matrix. What you want is not a big deal. REad about function max.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!