plotting multiple 2D point data in 3D

6 次查看(过去 30 天)
Hello,
I made my code to slice a 3D mesh and plot the sliced plane in 2D using mapshow(). So I have many slices planes as point set and would like to plot all plane in a 3D plot at once. Could you give me an idea?

回答(1 个)

Praveen Reddy
Praveen Reddy 2023-8-29
Hi Minyoung,
I understand that you want to plot planes in a 3D plot. You can use the surf” function to plot the planes. Below is an example where I have generated 2 planes and plotted them using the “surf” function.
% Generate sample 2D point data for the planes
x1 = randn(100, 1);
y1 = randn(100, 1);
z1 = zeros(size(x1));
x2 = randn(100, 1);
y2 = randn(100, 1);
z2 = ones(size(x2));
% Fit planes to the 2D point data
plane1 = fit([x1, y1], z1, 'poly11');
plane2 = fit([x2, y2], z2, 'poly11');
% Define the range of x and y values to plot the planes
[X, Y] = meshgrid(linspace(min([x1; x2]), max([x1; x2]), 10), ...
linspace(min([y1; y2]), max([y1; y2]), 10));
% Evaluate the plane equations at each point on the grid
Z1 = plane1(X(:), Y(:));
Z2 = plane2(X(:), Y(:));
% Reshape the Z values to match the grid size
Z1 = reshape(Z1, size(X));
Z2 = reshape(Z2, size(X));
% Plot the planes
figure;
surf(X, Y, Z1, 'FaceAlpha', 0.5);
hold on;
surf(X, Y, Z2, 'FaceAlpha', 0.5);
% Set labels and title
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Plane Fitting with 2D Point Data');
view(3);
axis equal;
Please refer to the following MATLAB documentation page to know more about the “surf” function:

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by