Clear Filters
Clear Filters

Find peaks of plot in UIAxes appdesigner

9 views (last 30 days)
Sam Quick
Sam Quick on 21 May 2019
Answered: Astha Singh on 3 Jun 2019
Dear everybody
I'm working on an app in appdesigner of matlab for a school project where we get a lot of data from an excel file, which we plot using uiaxes. The next step is to locate all the peaks of this plot and highlight them on the plot ( see picture below). We are allready able to find the peaks, but when trying to display them on the excisting window, it doen't work because it opens up a new figure... We tried to work wit the hold on function but it didn't work. This is the code we currently use:
app.data = xlsread(app.fileName, -1);
findpeaks(app.data, 'MinPeakDistance', 25);
plot(app.UIAxes, app.data)
peaks.PNG

Answers (1)

Astha Singh
Astha Singh on 3 Jun 2019
As per the workflow, 'hold on' should let the peak points be drawn on the same axis. For a simple example, try running the following in the MATLAB Command Window:
data = [25 8 15 5 6 10 10 3 1 20 7];
ax1=subplot(2,1,1);
plot(ax1,data)
hold on;
findpeaks(data)
This lets the original plot and the peaks to be in the same axis.
Also, as the 'findpeaks' function can return the location of the peak points, you can also plot the peaks as per the following manner:
data = [25 8 15 5 6 10 10 3 1 20 7];
ax1=subplot(2,1,1);
plot(ax1,data)
hold on;
[pks,locs] = findpeaks(data);
plot(ax1,locs,pks,'go')

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!