Finding the x value for a given y value on a plot

11 次查看(过去 30 天)
Hi,
I would like to get help with finding the corresponding x values for a given y value.
With reference to the plot that I have, I managed to find the peak values (as denoted by the blue arrows) for each curve of the graph. Now I would like to find the x values (time) for 30% and 90% of the peak y value (torque) that I found.
If possible, I would also like to know how I can find the highest slope/gradient of each curve on the graph between the times at 30% and 90% of the peak torque value.
x = TimeSeconds;
y = TorqueNewtonMeters;
graph = plot (x,y);
pks = findpeaks(y,'MinPeakProminence', 100);
thirtypercentpks = 0.3*pks;
ninetypercentpks = 0.9*pks;
Thank you!

回答(1 个)

Adam Danz
Adam Danz 2020-4-14
Check out the 2nd output to findpeaks, it gives you the x-values.
Check out the gradient() function to address the 2nd part of your question.
  4 个评论
Jaslyn Ong
Jaslyn Ong 2020-4-15
For now, I am still trying to determine the x values that correspond to 30% and 90% of the peak. If that y value falls between two coordinates, I intend to interpolate to a higher resolution.
But your method makes sense, I might try computing the distance from the peak's x-value and then subtracting that distance to get the x-value. May I ask what code I should apply to carry out this action?
The purpose of finding the x values is so that I am able to define the time period within which I will be extracting the slope/gradient (rate of torque development) from.
Thank you so much!
Adam Danz
Adam Danz 2020-4-15
编辑:Adam Danz 2020-4-17
1) You can use vq = interp1(x,v,xq) to resample the (x,y) data to a finer resolution. The finer the resolution, the smaller the error will be between the selected y-value and the actual y-value that represents the x% mark.
2) Compute the height of each peak. Then compute 30% and 90% of the peak value. Let's say that y value at the peak is p, the y value at the 30% mark would be p*.3.
3) Locate the closest values to p*.3 and p*.9 y-values just before and just after the peak. You may want to segment the curves from the closest near-0 y-value to the peak. There are lots of ways to approach this step so once you get here, try some approaches and let us know if you get stuck & show us what you've got.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by