MATLAB Answers

Extracting particular x and y data points from a figure

4 views (last 30 days)
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!

  0 Comments

Sign in to comment.

Accepted Answer

J. Alex Lee
J. Alex Lee on 11 Mar 2020
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 Comments

Milda Sirkaite
Milda Sirkaite on 12 Mar 2020
Thank you for your answer but somehow it does not work for me. Yes, this was just an example but my function is a bit more complicated:
E = 33*10^9;
fcm = 38*10^6;
eps_c1 = (0.7*(fcm*10^(-6))^(0.31))*10^(-3);
k = 1.05*E*eps_c1/fcm;
n = eps_c1/10;
eps0 = 0;
eps1 = n;
eps2 = 2*n;
eps3 = 3*n;
eps4 = 4*n;
eps5 = 5*n;
eps6 = 6*n;
eps7 = 7*n;
eps8 = 8*n;
eps9 = 9*n;
eps10 = eps_c1;
sig0 = 0;
sig1 = ((k*(eps1/eps_c1)-(eps1/eps_c1)^2)/(1+(k-2)*(eps1/eps_c1)))*fcm;
sig2 = ((k*(eps2/eps_c1)-(eps2/eps_c1)^2)/(1+(k-2)*(eps2/eps_c1)))*fcm;
sig3 = ((k*(eps3/eps_c1)-(eps3/eps_c1)^2)/(1+(k-2)*(eps3/eps_c1)))*fcm;
sig4 = ((k*(eps4/eps_c1)-(eps4/eps_c1)^2)/(1+(k-2)*(eps4/eps_c1)))*fcm;
sig5 = ((k*(eps5/eps_c1)-(eps5/eps_c1)^2)/(1+(k-2)*(eps5/eps_c1)))*fcm;
sig6 = ((k*(eps6/eps_c1)-(eps6/eps_c1)^2)/(1+(k-2)*(eps6/eps_c1)))*fcm;
sig7 = ((k*(eps7/eps_c1)-(eps7/eps_c1)^2)/(1+(k-2)*(eps7/eps_c1)))*fcm;
sig8 = ((k*(eps8/eps_c1)-(eps8/eps_c1)^2)/(1+(k-2)*(eps8/eps_c1)))*fcm;
sig9 = ((k*(eps9/eps_c1)-(eps9/eps_c1)^2)/(1+(k-2)*(eps9/eps_c1)))*fcm;
sig10 = fcm;
sig = [sig0 sig1 sig2 sig3 sig4 sig5 sig6 sig7 sig8 sig9 sig10]
eps = [eps0 eps1 eps2 eps3 eps4 eps5 eps6 eps7 eps8 eps9 eps10]
plot(eps, sig);
Then I get graph that I need but cannot get eps value, when my sig is for example 30*10^6.
I tried your option but it doesn't give me the value, maybe I do something wrong
J. Alex Lee
J. Alex Lee on 12 Mar 2020
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 on 12 Mar 2020
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.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags


Translated by