Finding the x value for a given y value on a plot
이전 댓글 표시
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
2020년 4월 14일
0 개 추천
Check out the 2nd output to findpeaks, it gives you the x-values.
[pks,locs] = findpeaks(data) <--link
댓글 수: 4
Jaslyn Ong
2020년 4월 14일
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
2020년 4월 15일
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.
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!