MATLAB: How to find the latest peak value of a curve.

curvelatestpeakpower

Hello,
I have a problem, i want to find the latest peak value of the following power curve. It is not the maximum power point, i've already found it earlier. But i should compare the latest value P(end) with P(end-1) and if P(end)<P(end-1) we should continue like this… to reach the point where P(i)>P(i-1) to come one value before, it will give me the latest peak power value.
Thank's for your help 😉 Jb

Best Answer

[pk,loc] = findpeaks(P(end:-1:1),'NPeaks',1);
[U(end-loc+1) pk]