在曲线中找到上升和下降的趋势MATLAB [英] Find the increasing and decreasing trend in a curve MATLAB

查看:885
本文介绍了在曲线中找到上升和下降的趋势MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

a=[2 3 6 7 2 1 0.01 6 8 10 12 15 18 9 6 5 4 2].

这里是一个数组,我需要提取出上升趋势和下降趋势开始的确切值.

Here is an array i need to extract the exact values where the increasing and decreasing trend starts.

数组a的输出将为[2(first element) 2 6 9]

a=[2 3 6 7 2 1 0.01 6 8 10 12 15 18 9 6 5 4 2].
   ^       ^        ^               ^
   |       |        |               |

请帮助我在MATLAB中获得任何类似类型的数组的结果.

Kindly help me to get the result in MATLAB for any similar type of array..

推荐答案

这是使用diff函数的好地方.

This is a great place to use the diff function.

您的第一步将是执行以下操作: B = [0 diff(a)]

Your first step will be to do the following: B = [0 diff(a)]

由于diff函数的工作方式,我们在其中加0的原因是为了使矩阵保持相同的长度.它将从矩阵中的第一个元素开始,然后报告该元素与下一个元素之间的差异.在第一个元素之前没有任何前导元素,因此仅将矩阵截断一个元素.我们添加一个零是因为那里没有变化,因为它是起始元素.

The reason we add the 0 there is to keep the matrix the same length because of the way the diff function works. It will start with the first element in the matrix and then report the difference between that and the next element. There's no leading element before the first one so is just truncates the matrix by one element. We add a zero because there is no change there as it's the starting element.

如果您查看B中的结果,现在很明显拐点在哪里(从正数到负数).

If you look at the results in B now it is quite obvious where the inflection points are (where you go from positive to negative numbers).

要以编程方式解决此问题,您可以执行许多操作.我倾向于使用一些乘法和find命令.

To pull this out programatically there are a number of things you can do. I tend to use a little multiplication and the find command.

Result = find(B(1:end-1).*B(2:end)<0)

这将返回您在拐点处的索引.在这种情况下,它将是:

This will return the index where you are on the cusp of the inflection. In this case it will be:

ans =

     4     7    13

这篇关于在曲线中找到上升和下降的趋势MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆