Finding Corresponding x axis values of a constant curve on Y-axis
7 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a curve similar to shown below in the image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/311996/image.jpeg)
I plan to find the 'x' values at which the function 'y' is maximum
I have denoted 'y' by 'cylpressure'
When i write the following,
[y,x] = max(cylpressure);
It returns me values
y = 400000
x= 118
But i need the values of 'x' when y starts to get constant(i.e. at x = 118, which i got from above code) and when y starts dwelling down(i.e at x = 180)
What changes must be done?
0 个评论
回答(1 个)
KSSV
2020-6-8
Let (x,y) be your data. Where y is cylpressure Dont use
[y,x] = max(cylpressure);
Rather, use:
[val,idx] = max(cylpressure);
In the baove val gives you maximum value of y and idx gives you index of the maximum value. You can get the respective value of x using x(idx).
If you know the value of x and you want to get corresponding y value use interp1.
yi = interp1(x,y,xi) ;
4 个评论
Sarah Nasra
2023-1-1
how we can do the opposite? if i know the y value and want to extract the x value?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!