how to check the direction of a plot (monotonicity)

2 次查看(过去 30 天)
I would like to check the percentage of data going forward instead of going backward in a data. For example in the following images:
the data should go from left to right, but for the second image, we can see that few data goes backward before it goes forward again.
1) I would like to check the percentage of the data forward in the overall data to check the monotonicity of the plot.
2) i would like to set a reference line, at different angle. for example, the below image can be seen at 0 degree from x axis. i would like to be able to set the reference line to perhaps 45 degree and see if teh monotinicity value of the plot would change if i change the angle. (because by rotating the axis, the monotonicity behaviour will change, where the data will look like it goes in forward direction instead of backward again

回答(1 个)

John D'Errico
John D'Errico 2016-3-30
编辑:John D'Errico 2016-3-30
Assuming that x is in increasing order, then something like this:
sum(diff(y) >= 0)/(numel(y) - 1)
will suffice to yield the relative fraction of points on the curve that lie in increasing order. Easily fixed if the points are not sorted for increasing x.
  2 个评论
Sharah
Sharah 2016-3-30
x and y is not in increasing order. it will be either decreasing or increasing depending on the performance. so here basically what need to be checked of the relationship between y-x is always in increasing order or not
John D'Errico
John D'Errico 2016-3-30
So whats the problem?
Just compute
d = diff(y)./diff(x);
If ANY of diff(x) == 0, then the curve is never monotone anyway. So you need for all of the elements of d to have the same sign and to be finite.
Test that all the elements of d are positive, OR they are all negative, AND they are all finite (not either inf or nan).
help all
help isfinite

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by