필터 지우기
필터 지우기

Plot Cubes in Matalb

조회 수: 9 (최근 30일)
Chad
Chad 2012년 1월 3일
답변: Raj Gopal Mishra 2020년 7월 25일
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