Search code examples
matlabmatlab-figurematlab-deployment

How to delete the same peak value in peak analysis and to find the duration of each event (which contain peak value)?


I am a newbie in matlab programming. Actually I have asked this question in mathwork website, but still I did not get the answer, so maybe I can get it here. I am trying to do peak analysis to find the peak flow of storm water flow. Here is my code :

%% Peak flow analysis
% define data which are used for analysis
Date=finalCSVnew{:,1};
Flow=finalCSVnew{:,7};

figure(2);
[pks,locs]=findpeaks(Flow,Date,'MinPeakProminence',1,'MinPeakDistance',1);  
findpeaks(Flow,Date,'MinPeakProminence',1,'MinPeakDistance',1);
text(locs+.02,pks,num2str((1:numel(pks))'));
xlabel('Date and Time');
ylabel('Flow [m3/h]');
title('Find All Peak Flows');
datacursormode on

I managed to plot the peak flow, and find the details about pks and locs. Here, each event should contain one peak flow. So in my case (based on attached picture) I should have 16 events. However, there is duplicate value in event 1 and event 2 which I want to delete one of them, but I am confused about how to do it. Also, I try to find the tutorial for calculating the duration of each event in the website, but I found nothing. I want to know about how to calculate the duration (probably in minutes) based on the peak flow data I got and to delete the peak value in the plot and in pks data which contain duplicates. Is it possible to do that? Could you please help me? Thank you very much for your help.peak flow events


Solution

  • For duplicate values, you can use the unique function to find values which are the same and remove them.

    C = unique(pks) % find any unique values and output values without repetitions
    

    https://au.mathworks.com/help/matlab/ref/unique.html

    Provide more details about the duration you want to measure. Do you want to measure the duration of just the peak flow? Or of the entire curve leading up to the peak?