Finding the x value for a given y value on a plot
Show older comments
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!
Answers (1)
Adam Danz
on 14 Apr 2020
0 votes
Check out the 2nd output to findpeaks, it gives you the x-values.
[pks,locs] = findpeaks(data) <--link
4 Comments
Jaslyn Ong
on 14 Apr 2020
I see. Before you edited the question, it seemed that you were trying to find the x values for 30-90% of your peaks.
How far are you in solving this? For example, there are at least two ways to define the 30% and 90% marks. Are you describing the x% of the vertical distance between some baseline and the peak?
If that y value falls between two coordinates, do you intend to choose the closest one, or do you indend to interpolate to higher resolution?
Once you have the y-coordinate that approximates (or exactly matches) the y-value of the x% mark, you can compute its distance from the peak's x-value and then add/subtract that distance to get the x-value.
Jaslyn Ong
on 15 Apr 2020
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.
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!