필터 지우기
필터 지우기

Extracting particular x and y data points from a figure

조회 수: 11 (최근 30일)
Milda Sirkaite
Milda Sirkaite 2020년 3월 11일
댓글: Milda Sirkaite 2020년 3월 12일
Hello,
I was wondering is it possible to extract particular x data point from a graph if I have y point value? For example, I enter x and y values:
x = 0 10 20 30 40 50 60 70 80
y = 0 3 6 9 12 15 18 21 24
With plot function I get a graph. But then I have y value 8, is it possilble to get x value? It is not suitable for me to use data cursor, I need that value in command window.
Thank you for all your information!

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 3월 11일
Thinking in terms of graphs is useful but only takes you so far. The point is how to think about the data and/or functions underlying the graph.
You are looking for "interpolation" strategies.
Since both x and y look well behaved, you can achieve what you want simply by
x = [0 10 20 30 40 50 60 70 80]
y = [0 3 6 9 12 15 18 21 24]
yTarget = 8
xTarget = interp1(y,x,yTarget,"linear")
% check graphically
hold on;
plot(x,y)
plot(xTarget,yTarget,'*')
In fact, upon trying above and actually looking at your data, you have labored to define a very simple line, which by inspection has the form
So for your specific problem just do algebra
But anyway the procedure in the code above will work well as long as y is monotonic.
  댓글 수: 3
J. Alex Lee
J. Alex Lee 2020년 3월 12일
can you update your code with your application of my suggestion, and describe exactly how it is failing, or errors it is producing? Also you can use the "insert code" button in the editor (or alt+enter) to write code so that it is easier for people to follow.
you will benefit from learning how to define arrays in loops or with vectorial statements, e.g.,
eps = (0:10)*n
and also reviewing issues with computer-representation of numbers that vary greatly in order of magnitude. In this case, it seems not to have made a difference, but you have lots of redundant multiplications and divisions by millions and billions.
Milda Sirkaite
Milda Sirkaite 2020년 3월 12일
Thank You so much! I tried again and it worked just like I needed. I'm sorry if I had trouble to explain what I'm looking for, I don't know matlab very good, only basics.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by