matlab 可以在图中找到多个峰吗?

Can matlab find multiple peaks in a plot?

显然我是 matlab 编程的新手。我的老师给了我们一个关于编程的问题,他要我们使用 matlab 编写一个程序,可以 find/locate peak/s 来自数据图,这是一种峰值查找器。我可以使用 origin pro 和 scilab(它们是峰值查找软件)来做到这一点,那么 matlab 可以做到这一点吗?提前致谢。

您可以使用findpeaks函数:

x = [0:.01:50];
y = cos(x);
[val, pos] = findpeaks(y, x)
  val =
     1.0000    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
  pos =
     6.2800   12.5700   18.8500   25.1300   31.4200   37.7000   43.9800

或者,如果您想要更图形化的内容:

x = [0:.01:50];
y = cos(x);
plot(x, y);
findpeaks(y, x);

无论如何,您应该查看 findpeaks 文档以获取更多信息:

doc findpeaks