Find coordinates of border in findpeaks plot
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luca de Freitas
el 5 de Ag. de 2021
Comentada: Star Strider
el 5 de Ag. de 2021
Hi all,
I am struggling to find the cooridnates for the borders value while using the findpeaks function.
Here is a picture of my plot:
I would need to find the x coordinates of the borders between the peaks. I am doing so in order to get the duration of each peak delimited by the purble borders.
My code right now looks like this:
load('pO2,Mean,Numeric,Float,Raumedic,data_part1of1.mat');
ox = measurement_data;
smooth_ox = smooth(ox, 0.01, 'loess');
%find peaks
[pks,locs,wdths] = findpeaks(smooth_ox,'MinPeakProminence',0.5);
locmax = islocalmax(smooth_ox);
%plot
figure()
findpeaks(smooth_ox,'MinPeakProminence',0.5,'Annotate','extents',...
'WidthReference','halfheight')
text(locs+.02,pks,num2str((1:numel(pks))'))
title('Peaks')
Thank you for the help!
0 comentarios
Respuesta aceptada
Star Strider
el 5 de Ag. de 2021
Using an example from the findpeaks documentation —
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;
Gauss = Hgt.'.*exp(-((x-Pos.')./Wdt.').^2);
smooth_ox = sum(Gauss);
%find peaks
[pks,locs,wdths] = findpeaks(smooth_ox,'MinPeakProminence',0.5);
locmax = islocalmax(smooth_ox);
%plot
figure
findpeaks(smooth_ox,'MinPeakProminence',0.5,'Annotate','extents',...
'WidthReference','halfheight')
text(locs+.02,pks,num2str((1:numel(pks))'))
title('Peaks')
Ax = gca; % Axes Handle
% GetAx = get(Ax) % Explore ...
% GetAx.Children % Explore ...
hlb = findobj(Ax,'Type','line', 'tag','Border') % Handles Array To Linew Sith 'Border' Tag
hlb(1).XData % Desired Result
hlb(2).XData % Desired Result
It might be necessary to use a for loop to get all of them in your situation (data not provided), however it should be straightforward to get them using this approach:
for k = 1:numel(hlb)
BorderX(k,:) = hlb(k).XData;
end
BorderX % View Result
Make appropriate changes to get the result you want.
.
2 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!