Fun*_*unc 17 grid matlab plot cube
嗨,我想绘制带有线条的透明立方体网格.像这样的东西:

但是,我只设法绘制2D网格:
[X,Y] = meshgrid(-8:.5:8);
Z = X+1;
surf(X,Y,Z)
Run Code Online (Sandbox Code Playgroud)
我使用Matlab R2009b.如果不可能在matlab中绘制这个,你可以向我推荐一个我可以使用的软件.
Amr*_*mro 19
考虑这个矢量化解决方案.它的优点是它创建了一个图形对象:
%# these don't all have to be the same
x = -8:2:8; y = -8:2:8; z = -8:2:8;
[X1 Y1 Z1] = meshgrid(x([1 end]),y,z);
X1 = permute(X1,[2 1 3]); Y1 = permute(Y1,[2 1 3]); Z1 = permute(Z1,[2 1 3]);
X1(end+1,:,:) = NaN; Y1(end+1,:,:) = NaN; Z1(end+1,:,:) = NaN;
[X2 Y2 Z2] = meshgrid(x,y([1 end]),z);
X2(end+1,:,:) = NaN; Y2(end+1,:,:) = NaN; Z2(end+1,:,:) = NaN;
[X3 Y3 Z3] = meshgrid(x,y,z([1 end]));
X3 = permute(X3,[3 1 2]); Y3 = permute(Y3,[3 1 2]); Z3 = permute(Z3,[3 1 2]);
X3(end+1,:,:) = NaN; Y3(end+1,:,:) = NaN; Z3(end+1,:,:) = NaN;
%#figure('Renderer','opengl')
h = line([X1(:);X2(:);X3(:)], [Y1(:);Y2(:);Y3(:)], [Z1(:);Z2(:);Z3(:)]);
set(h, 'Color',[0.5 0.5 1], 'LineWidth',1, 'LineStyle','-')
%#set(gca, 'Box','on', 'LineWidth',2, 'XTick',x, 'YTick',y, 'ZTick',z, ...
%# 'XLim',[x(1) x(end)], 'YLim',[y(1) y(end)], 'ZLim',[z(1) z(end)])
%#xlabel x, ylabel y, zlabel z
axis off
view(3), axis vis3d
camproj perspective, rotate3d on
Run Code Online (Sandbox Code Playgroud)

St-*_*hen 13
如果你不介意几个for循环,这样的东西将起作用:
clf
figure(1)
for g = 0:.2:2
for i = 0:.2:2
plot3([g g], [0 2], [i, i])
hold on
end
end
for g = 0:.2:2
for i = 0:.2:2
plot3([0 2], [g g], [i, i])
hold on
end
end
for g = 0:.2:2
for i = 0:.2:2
plot3([i i], [g g], [0 2])
hold on
end
end
Run Code Online (Sandbox Code Playgroud)
你只需要通过改变线属性来使网格透明,我认为你不能改变alpha值来实现这一点.希望有所帮助.
小智 11
Stephen的答案的更多矢量化版本可能如下:
i = 0:0.2:2;
[X Y] = meshgrid(i,i);
x = [X(:) X(:)]';
y = [Y(:) Y(:)]';
z = [repmat(i(1),1,length(x)); repmat(i(end),1,length(x))];
col = 'b';
hold on;
plot3(x,y,z,col);
plot3(y,z,x,col);
plot3(z,x,y,col);
Run Code Online (Sandbox Code Playgroud)
不幸的是,MATLAB目前不支持透明线(据我所知).如果你真的需要它们是透明的,我建议使用'patch'.