Extracting certain set of points from a 3D plot

Hi team,
I'm a novice in MATLAB. I've prepared a 3D plot using MATLAB script shown below with D1, D2 and total power values in the X, Y and Z - axes respectively.
Can a suggest a line of code or command where I give a range of power values and get a specific set of X and Y coordinate points (kinda like drawing an imaginary 3D plane in the plot and setting it at Z = some power and extracting all points that lie on that plane)? It would be really helpful.

 Accepted Answer

I would use the contour function for this.
Example —
[X,Y] = ndgrid(-3:0.1:3);
f = @(x,y) exp(-(x.^2+y.^2*3)*0.75);
Z = f(X,Y);
PowerVal = 0.41254;
figure
surf(X, Y, Z)
hold on
[c,h] = contour3(X, Y, Z, [1 1]*PowerVal, '-r', 'LineWidth',3);
hold off
colormap(turbo)
xv = c(1,2:end);
yv = c(2,2:end);
figure
plot(xv, yv)
grid
axis('equal')
axis('padded')
title("(X,Y) Coordinates At Power Value "+PowerVal)
I use contour3 here to draw the red line at the chosen level, to illustrate the idea. The contour functions only return the surface coordinates.
.

5 Comments

Thanks a lot @Star Strider. Really appreciate the help.
@Star Strider One more thing. I would also like to correlate the contour points with another variable 'phi', which is the another variable from which the above mentioned 3D plot was made. Based on the X and Y coordiates from the contour and 'phi', suggest me a line of code to make a plot based on these 3 variables?
As always, my pleasure!
I would have to know more about ‘phi’ and how it relates to the surface to provide a specific response.
If you only wanted to plot ‘phi’ as a function of ‘x’ and ‘y’ returned by the contour function, the plot3 function would be my recommendation, however that requires that all the vectors have equal sizes. It might be necessary to use an interpolation function of some sort to return appropriate values of ‘phi’ that matches the returned values of ‘x’ and ‘y’.
It would also help to have the data and code that plots the surface, as well as ‘phi’, for me to provide a specific response, and perhaps a function that would do all of that for a specific power value.
@Star Strider I've understood what you said. I will try implementing it. Thanks once again.
As always, my pleasure!

Sign in to comment.

More Answers (0)

Products

Release

R2023a

Asked:

on 26 Mar 2024

Commented:

on 1 Apr 2024

Community Treasure Hunt

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

Start Hunting!