MATLAB: Counting total number of peaks in an array?

signal processingSignal Processing Toolbox

I have attached a figure in which i have peaks at certain locations of certain duration.. I need the total number of peaks in the figure. For example, the number of peaks in this figure is 3. Can someone help me??

Best Answer

numel(findpeaks(your_signal))
%or
numel(gradient(your_signal)==0)