MATLAB Answers

How to obtain y value when x and z are given in matlab 3D plots

7 views (last 30 days)
Hi,
I have a 3D plot as shown in the attachment. You can see a data point x=0.25, y=2.25, z=0.27599 in the first curve. I want to find the corresponding y point of the second curve, when z=0.27599 and, x=0.50(second curve) for the second curve are given. Similar way I want to find the corresponding y point when z=0.27599 in the third curve and so on.
Your kind help will be greatly appreciated.

  0 Comments

Sign in to comment.

Accepted Answer

Dimuthu Dharshana Arachchige
First, it is suggested to obtain the 2D plot.
Then use this function. InterX
P = InterX([P2S;phiS],[P2S;Y]);
plot(P2S,phiS,P2S,Y,P(1,:),P(2,:),'ro'); grid on;xlabel('P2');ylabel('Phi'); hold on;

  0 Comments

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 1 Jul 2020
interp1() should do it. Did you try it?

  3 Comments

Dimuthu Dharshana Arachchige
Thank you 'Image Analyst'. I used a different method. interp1() will work. But it needs some work.
Image Analyst
Image Analyst on 2 Jul 2020
Well everything requires work but I don't think one single line of code is a huge amount of work, especially compared to downloading some third party function from the File Exchange. Look, here's a demo where I create data and find out the x value where the curve is equal to some specified y values. And you can see it's one single line of code:
% Create function and plot it.
P2 = linspace(0, 4, 8);
Phi = 1 - cos(2 * pi * P2 / 8);
plot(P2, Phi, 'b.-', 'MarkerSize', 20);
grid on;
xlabel('P2', 'FontSize', 20);
ylabel('Phi', 'FontSize', 20);
yline(1.1, 'Color', 'r');
% Now find x when y = 1.1. This is the single line of code you need.
x = interp1(Phi, P2, 1.1)
% Done! Now place a marker and line at that point.
xline(x, 'Color', 'r');
hold on;
plot(x, 1.1, 'rs', 'MarkerSize', 20, 'LineWidth', 2);
After it hits the x= line of code, it puts this in the command window:
x =
2.12839883449814
I mean, it really can't get much easier than that.
Dimuthu Dharshana Arachchige
Thank you. I greatly appreciate your work and it is much more easier than my method. I tried it. These P2 values were collected from some experimetns. My P2 contains Nan values. Therefore, I recieve the following error.

Sign in to comment.

Products


Release

R2019b

Translated by