Finding two values for y in a graph with the same x value

8 views (last 30 days)
So I made a plot
y=0.01:0.01:4
for i=1:length(y)
x(i)=sqrt(1/(y(i)^2)*(0.8+0.2*y(i)^2)^(20/3));
end
plot(x,y)
and i want to extract the values for x=6 I did this with interp1
ya = (interp1(x,y,6,'cubic'));
which works, but it only works for one value (the graph is a sideways parabola), but I want to extract both of them
  1 Comment
Image Analyst
Image Analyst on 1 Oct 2014
You forgot to post x and y. Make it easy for us to help you and maybe someone will. For example, post data for x and y and code to read them in from a data file if necessary, and include screenshots. Right now I have no idea what your curve looks like. Here, read this http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer then improve your post.

Sign in to comment.

Answers (2)

dpb
dpb on 1 Oct 2014
You'll have to use interp1 on the two branches of the y vector. This would essentially be using two sub-vectors from 1:location(min(x)) and then from that point:end for the two halves of the parabola.
  2 Comments
harry
harry on 1 Oct 2014
Edited: harry on 1 Oct 2014
a=1:location(min(y))
b=location(min(y)):end
y1 = (interp1(x,a,6,'cubic'));
y2 = (interp1(x,b,6,'cubic'));
like this? because this doesnt work: undefinede function of location for input arguments of type double
dpb
dpb on 1 Oct 2014
Edited: dpb on 1 Oct 2014
I wrote pseudocode description of the logic to implement, not Matlab code.
location(min(x)) would actually be
[~,iminx]=min(x);
It also needs be the minimum on x, not y if the parabola is open to the right as the original post says, not to the top or bottom. And, of course, if it's open to the left, it's a maximum, not minimum location you're looking for.

Sign in to comment.


Star Strider
Star Strider on 1 Oct 2014
We still don’t have your data, so I got creative:
f = @(x) [sqrt(x(:)) -sqrt(x(:))] + 10;
x = linspace(0, 10, 25);
y = f(x);
y_hi = y(:,1);
y_lo = y(:,2);
xidx = find((x >= 4) & (x <= 8));
hi_br = interp1(x, y_hi, 6);
lo_br = interp1(x, y_lo, 6);
figure(1)
plot(x, y)
hold on
plot(6, hi_br, '^r')
plot(6, lo_br, 'vr')
hold off

Community Treasure Hunt

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

Start Hunting!