本文主要是介绍matlab画三维空间劣弧,matlab 三维空间画图总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
matlab 三维画图总结
1.画函数的三维图,如:Z(X,Y)=2*X.*exp(-X.^2-Y.^2)+1;
close all;
[X,Y]=meshgrid(-2:0.5:2,-2:0.5:2);%生成坐标轴
Z=2*X.*exp(-X.^2-Y.^2)+1;%Z是X,Y的函数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=0;
num=num+1;
subplot(2,3,num);
plot3(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(1)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
mesh(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(2)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshc(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(3)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(4)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshz(X,Y,Z);
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(5)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
hold on;
stem3(X,Y,Z,'r');%画竖线
axis([-3 3 -3 3 0 2]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(6)');%标题
2.画矩阵的三维图
clc;
clear all;
close all;
X=[0 1 2 3 4 5 6 7 8 9];
Y=[0 1 2 3 4 5 6 7 8 9];
for i=1:1:length(X)
for j=1:1:length(Y)
Z(i,j)=mod(i*j*rand(1),9);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=0;
num=num+1;
subplot(2,3,num);
plot3(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(1)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
mesh(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(2)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshc(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(3)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(4)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
meshz(X,Y,Z);
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(5)');%标题
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
num=num+1;
subplot(2,3,num);
surf(X,Y,Z);
hold on;
stem3(X,Y,Z,'r');%画竖线
axis([0 9 0 9 0 9]);%限定显示的范围
xlabel('x轴');%x轴坐标
ylabel('y轴');%y轴坐标
zlabel('z轴');%z轴坐标
title('http://blog.csdn.net/nuptboyzhb/ figure(6)');%标题
3.画矩阵的颜色深度图
我自己编写的一个函数:graycolor.m
%filename:graycolor.m
%郑海波 2013-01-31
%http://blog.csdn.net/nuptboyzhb/
%原理:灰度图像的伪彩色处理
%值越大,显示的颜色越蓝,越小,显示的颜色越红!
%参数:newbuf必须使二维数组或矩阵
function graycolor(newbuf);
min_n=min(min(newbuf));
max_n=max(max(newbuf));
newbuf=newbuf./(max_n-min_n)*255;
[M N]=size(newbuf);
for i=1:1:M
for j=1:1:N
R(i,j)=GrayColorR(newbuf(i,j));
G(i,j)=GrayColorG(newbuf(i,j));
B(i,j)=GrayColorB(newbuf(i,j));
end
end
img(1:1:M,1:1:N,1)=R(1:M,1:N);
img(1:1:M,1:1:N,2)=G(1:M,1:N);
img(1:1:M,1:1:N,3)=B(1:M,1:N);
imshow(uint8(img));
function r=GrayColorR(gray)
r=0;
if gray>=170
r=255;
end
if gray>=128&&gray<=170
r=255/42*(gray-128);
end
return;
function g=GrayColorG(gray)
g=0;
if gray>=84&&gray<=170
g=255;
end
if gray<=84
g=255/84*gray;
end
if gray>=170&&gray<=255
g=255/85*(255-gray);
end
return;
function b=GrayColorB(gray)
b=0;
if gray<=84
b=255;
end
if gray>=84&&gray<=128
b=255/44*(128-gray);
end
return;
函数的调用:
[X,Y]=meshgrid(-2:0.01:2,-2:0.01:2);%生成坐标轴
Z=2*X.*exp(-X.^2-Y.^2)+1;%Z是X,Y的函数
graycolor(Z);
title('http://blog.csdn.net/nuptboyzhb/');%标题
另外,在\matlab2009a\toolbox\matlab\demos\graf3d.m中文件,有更加详细的介绍。界面如下:
这篇关于matlab画三维空间劣弧,matlab 三维空间画图总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!