作业帮 > 英语 > 作业

matlab中,如何用离散的三维坐标画出仅以z坐标值确定的三维柱状图.

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/06 10:55:16
matlab中,如何用离散的三维坐标画出仅以z坐标值确定的三维柱状图.
坐标三维,通过文件读入.我想画一个在xy坐标确定的二维平面上再用z坐标值画出其值相对应高度的圆柱(或直方图都行),即得到能直观表现出相应地点高度的三维柱状图(不是每一点的坐标都给出了),不知道我说明白了没有,可以hi我,急,
function voxel(i,d,c,alpha);
%VOXEL function to draw a 3-D voxel in a 3-D plot
%
%Usage
% voxel(start,size,color,alpha);
%
% will draw a voxel at 'start' of size 'size' of color 'color' and
% transparency alpha (1 for opaque,0 for transparent)
% Default size is 1
% Default color is blue
% Default alpha value is 1
%
% start is a three element vector [x,y,z]
% size the a three element vector [dx,dy,dz]
% color is a character string to specify color
% (type 'help plot' to see list of valid colors)
%
%
% voxel([2 3 4],[1 2 3],'r',0.7);
% axis([0 10 0 10 0 10]);
%
% Suresh Joel Apr 15,2003
% Updated Feb 25,2004
switch(nargin),
case 0
disp('Too few arguements for voxel');
return;
case 1
l=1; %default length of side of voxel is 1
c='b'; %default color of voxel is blue
case 2,
c='b';
case 3,
alpha=1;
case 4,
%do nothing
otherwise
disp('Too many arguements for voxel');
end;
x=[i(1)+[0 0 0 0 d(1) d(1) d(1) d(1)]; ...
i(2)+[0 0 d(2) d(2) 0 0 d(2) d(2)]; ...
i(3)+[0 d(3) 0 d(3) 0 d(3) 0 d(3)]]';
for n=1:3,
if n==3,
x=sortrows(x,[n,1]);
else
x=sortrows(x,[n n+1]);
end;
temp=x(3,:);
x(3,:)=x(4,:);
x(4,:)=temp;
h=patch(x(1:4,1),x(1:4,2),x(1:4,3),c);
set(h,'FaceAlpha',alpha);
temp=x(7,:);
x(7,:)=x(8,:);
x(8,:)=temp;
h=patch(x(5:8,1),x(5:8,2),x(5:8,3),c);
set(h,'FaceAlpha',alpha);
end;
可以用此函数做图
例如
>> clear
M=diag([1,-1,2,-2,3]);
[l1,l2]=size(M);
hold on
for i=1:l1
for j=1:l2
if abs(M(i,j))>eps
voxel([i,j,0],[.3,.3,M(i,j)],.7);
end
end
end
grid on
view([65,22])
hold off