Find peaks of plot in UIAxes appdesigner

9 次查看(过去 30 天)
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

回答(1 个)

Astha Singh
Astha Singh 2019-6-3
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')

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics and Visualization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by