MATLAB: Flipping y-axis of findpeaks-plot

arrayplotreverseplot

Hi!
To find minima-values of an array I multiplied my array with -1 and used findpeaks. To graphically show the minimas I want to reverse the findpeaks-plot but can't figure out how. Any suggestions?
E_bat3 = E_bat2.*(-1);
findpeaks(E_bat3(winter_hours)) %Graph I want to flip.
Thanks!

Best Answer

You may be making this too difficult.
Example
a = linspace(0, 4*pi);
y = sin(a);
[pks,pkloc] = findpeaks( y,a); % Maxima
[vls,vlloc] = findpeaks(-y,a); % Minima

figure(1)
plot(a, y, '-b')
hold on
plot(pkloc, pks, '^r', 'MarkerFaceColor','r')
plot(vlloc, -vls, 'vg', 'MarkerFaceColor','g')
hold off
grid
axis([xlim -1.1 1.1])
legend('Data', 'Peaks', 'Valleys')
Note that to plot the valleys (‘vls’) or minima correctly, simply negate them in the plot call. So to find them, use:
[vls,vlloc] = findpeaks(-y,a); % Minima
and to plot them or use them in other calculations correctly, negate them again to restore their correct values:
plot(vlloc, -vls, 'vg', 'MarkerFaceColor','g')