Plot Cubes in Matalb

4 次查看(过去 30 天)
Chad
Chad 2012-1-3
Hi...I have a question about plotting cubes in Matlab. I have a program that generates n-cubes where each cube has a value associated with it. For example, I start with a simple 3x3x3 center that represents the center of cube and I have a value for each cube. So I have
CubeCenter = 3x27: Where column 1 is x, column 2 is y, and column 3 is the z coordinates.
CubeCenterValue = 1x27: Where is I have the value for each cube center.
Is there a way to plot the 27 cubes where it has a different color. Furthermore, is there a way to plot the cubes in 3-d and also plot a cross-section of just 9 of the cubes in 2-d with a different color.
Thanks in advance...Chad

回答(1 个)

Raj Gopal Mishra
Raj Gopal Mishra 2020-7-25
Cube Plot
X=linspace(-1,1,101); % Define point on x axis
Y=ones(size(X)); % define points of y axis
Z=Y;% define point on z axis
%%SURFACE AT Z=1
plot3([X fliplr(X)], [Y (-1*Y)], [Z (Z)],'r')
xlabel('X')
hold on
%%SURFACE AT Z=-1
plot3([X fliplr(X)],[Y (-1*Y)],[(-1*Z) (-1*Z)],'b')
xlabel('X')
hold on
%%SURFACE AT Y=1
plot3([X fliplr(X)], [Y Y], [Z (-1*Z)], 'k')
ylabel('Y')
hold on
%%SURFACE AT Y=-1
plot3([X fliplr(X)],[(-1*Y) (-1*Y)], [Y (-1*Y)], 'y')
ylabel('Y')
hold on
%%SURFACE AT X=1
plot3([Z Z], [Y (-1*Y)],[X fliplr(X)], 'm')
zlabel('Z')
hold on
%%SURFACE AT X=-1
plot3([(-1*Z) (-1*Z)], [Y (-1*Y)],[X fliplr(X)], 'c')
zlabel('Z')
hold off
grid
Cube Patch
X=linspace(-1,1,101); % Define point on x axis
Y=ones(size(X)); % define points of y axis
Z=Y;% define point on z axis
figure
%%SURFACE AT Z=1
patch([X fliplr(X)], [Y (-1*Y)], [Z (Z)],'r')
xlabel('X')
hold on
%%SURFACE AT Z=-1
patch([X fliplr(X)],[Y (-1*Y)],[(-1*Z) (-1*Z)],'b')
xlabel('X')
hold on
%%SURFACE AT Y=1
patch([X fliplr(X)], [Y Y], [Z (-1*Z)], 'k')
ylabel('Y')
hold on
%%SURFACE AT Y=-1
patch([X fliplr(X)],[(-1*Y) (-1*Y)], [Y (-1*Y)], 'y')
ylabel('Y')
hold on
%%SURFACE AT X=1
patch([Z Z], [Y (-1*Y)],[X fliplr(X)], 'm')
zlabel('Z')
hold on
%%SURFACE AT X=-1
patch([(-1*Z) (-1*Z)], [Y (-1*Y)],[X fliplr(X)], 'c')
zlabel('Z')
hold off
grid
view(40,40)

类别

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