【源码】自动标记曲线的局部最大值和最小值

在这里插入图片描述

很容易让你自动找到、绘图并标记局部极大值(峰值)和局部极小值的MATLAB代码。

Easily allows you to automatically find, plot, and label local maxima (peaks) and local minima on MATLAB

This code requires the MATLAB Signal Processing Toolbox, which can be downloaded here: https://www.mathworks.com/products/signal.html

How to use these functions:

You just need your “x” and “y” arrays, as you would do for a simple plot(x,y), and just 2 numbers: “hs” controls the horizontal space between peaks/dips and their respective labels ((+): right, (-): left), and “vs” controls the vertical spacing. If in doubt, set hs=0 and vs=0.

[pks,locs] = PeakDipLabels(x,y,hs,vs)

  • PeakDipLabels: find, plot, and label both peaks (red) and dips (green).

  • PeakLabels: find, plot, and label just peaks (red).

  • DipLabels: find, plot, and label just dips (green).

How to install these files:

  1. This code was written using MATLAB (version 2020a). Download MATLAB on your computer or try MATLAB online

  2. As mentioned above, you’ll need to have the MATLAB Signal Processing Toolbox installed

  3. Download the 3 files on this repository: “PeakDipLabels.m”, “PeakLabels.m”, and “DipLabels.m”

  4. Once downloaded, copy these function files to the MATLAB parent directory. On Windows, this is typically: C:\Users\YourUserName\Documents\MATLAB

  5. That’s it! You should be able to use these 3 functions

Example:

hs = 0; vs = 0;

x = linspace(-20,20,1000);

y = exp(-x/10).* cos(x)

PeakDipLabels(x,y,hs,vs)

% alternatively, you can run [pks,locs] = PeakDipLabels(x,y,hs,vs) instead of PeakDipLabels(x,y,0,0) if you want to save arrays of peaks/dips and their locations to workspace

更多精彩文章请关注公众号:在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值