how to find value of y from a graph with a known x value

조회 수: 9 (최근 30일)
Ross Hanna
Ross Hanna 2017년 8월 12일
댓글: Ross Hanna 2017년 8월 13일
Hi There
I already have another question up on this subject but i think i may be over-complicating what i'm trying to ask. In the file i have attached, i have a graph that i have plotted from the data in the worksheet. what i am trying to do is find for values of x, not limited to the data i have, find the corresponding y values. after some reading i think i would have to use interp1, but that came with some issues when i tried to implement it (The grid vector must contain unique points' error and then 'Vectors must be the same lengths') and also use index. would i have to interpolate first to get numbers in incrementys of 1 or 2 etc then use index=find?
thanks, Ross

채택된 답변

Chad Greene
Chad Greene 2017년 8월 12일
Hi Ross,
The data you provide make a multi-valued function. There are several possibly y values for any given x value, so interp1 would not be a valid way to get an answer. Even if you flip the x and y, it's still multi-valued.
Depending on your application, you might be able to think of each x value and each y value as functions of distance along the path. The distance along the path would be something like
d = [0;cumsum(hypot(diff(x),diff(y)))];
Then if you want to get the points xi,yi at some distance di, it would be
xi = interp1(d,x,di);
yi = interp1(d,y,di);
  댓글 수: 1
Ross Hanna
Ross Hanna 2017년 8월 13일
im relatively new to matlab, and trying to execute this is problematic. if i import my data e.g. Force and Velocity, then type in your code, it comes up as "undefined function or variable 'di'". What should i set di equal to? if i set it equal to say 400N it says
Error using griddedInterpolant The grid vectors must contain unique points.
Error in interp1 (line 161) F = griddedInterpolant(X,V,method);
do i have to set it equal to a point in the data i have?
what i am trying to do is write a code that i can give it any value from 1-1400 for example and it will give me the y values associated with them and then i can average them. i looked at your other answer using the scatstat1 function but i dont know if i have to download a file that has it in for example?
Thanks for your reply

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by