I have minimums and maximums in the output now (Fig.1) but I would like to get labels (Fig. 2) for sorted maximums (tallest get 1, ...) and similarly for minimums (lowest gets 1). I can do the output of Fig. 1 by the following but I cannot integrate those annotations to the function
close all; clear all; clc;
% https://se.mathworks.com/help/signal/ref/findpeaks.html
% http://stackoverflow.com/a/26837689/54964
x = linspace(0,1,1000);
Pos = [1 2 3 5 7 8]/10;
Hgt = [4 4 2 2 2 3];
Wdt = [3 8 4 3 4 6]/100;
for n = 1:length(Pos)
Gauss(n,:) = Hgt(n)*exp(-((x - Pos(n))/Wdt(n)).^2);
end
PeakSig = sum(Gauss) - exp(sum(Gauss))/10;
plot(x, PeakSig);
hold on;
[p l]=findpeaks(PeakSig); %,x); %,'Annotate','extents','WidthReference','halfheight')
plot(x(l), p, 'ko', 'MarkerFaceColor', 'g');
[pn ln]=findpeaks(-PeakSig); %,x); %,'Annotate','extents','WidthReference','halfheight')
plot(x(ln), -pn, 'ko', 'MarkerFaceColor', 'r');
title('Signal Peak Widths')
To just append 'Annotate','extents','WidthReference','halfheight')
to [p l]=findpeaks(...)
is not working in the application etc the following apparently because the proceeding line plot(x(l), p, 'ko', 'MarkerFaceColor', 'g');
does not understand the extra content made by the one-liner in the corresponding variables
[p l]=findpeaks(PeakSig,'Annotate','extents','WidthReference','halfheight')
[p l]=findpeaks(PeakSig, x, 'Annotate','extents','WidthReference','halfheight')
Fig. 1 Current output without those annotations, Fig. 2 Expected output but with notes of maximums and minimums
MATLAB: 2016b
OS: Debian 8.5 64 bit
Hardware: Asus Zenbook UX303UA