Cross section of a plot (surface, Imagesc) using an arbitrary line
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Contoso Donoso am 9 Mär. 2023
Beantwortet: Contoso Donoso am 10 Mär. 2023
I have a plot of surface(x,y,z) (or an imagesc) and want to draw an arbitrary line to get the z information following that path.
So I have two questions:
First, how to draw a path that coincides with my x,y grid? Let's say I want a semicircular path, but it can be whichever.
And second, how do I get the values that correspond to the Z information that follows that said path?
I am not sure if what I am asking is too complex to answer, but I would love to hear your comments,
Thanks in advance.
Cameron am 9 Mär. 2023
Bearbeitet: Cameron am 9 Mär. 2023
You can do this by interpolating. Depending on your requirements, you can use cubic, nearest neighbor, makima, linear, or spline interpolation. Here's an example:
[X,Y] = meshgrid(-5:.5:5); %some x and y data
Z = Y.*sin(X) - X.*cos(Y); %some z data
s = surf(X,Y,Z,'FaceAlpha',0.5); %surface plot
s.Parent.View = [0 90]; %view the plot
x1 = -2:0.1:2; %some x path
y1 = 3*sin(2*x1); %some y path
InterpStyle = 'spline'; %you can choose cubic, nearest, makima, linear, or spline
z1 = interp2(X,Y,Z,x1,y1,'cubic',0); %your interpolated z values
plot3(x1,y1,z1,'-k','LineWidth',2) %show the new data
s.Parent.View = [12 25]; %you can change the view to see what the black line looks like in 3D
Weitere Antworten (3)
Image Analyst am 9 Mär. 2023
That's exactly what my attached demo does. It allows you to draw over your image with drawfreehand and then plots the image values underneath where you drew:
Steven Lord am 9 Mär. 2023
Others have spoken about the mathematics behind taking coordinate data of your math and generating the Z data. If you're having difficulty in the first part of the problem, generating the coordinate data, some options include using the ginput function to let you click points on the plot (for which I'd probably use a 2-D view of your surface, view(2), so you're clicking from "directly overhead") or using the improfile function from Image Processing Toolbox (if you're operating on image data or can treat your data as image data.)
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!