打印

matlab 三维画图总结

[复制链接]
907|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
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)');%标题

相关帖子

沙发
gaoyang9992006|  楼主 | 2017-6-22 16:30 | 只看该作者
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)');%标题

使用特权

评论回复
板凳
gaoyang9992006|  楼主 | 2017-6-22 16:32 | 只看该作者

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/');%标题


使用特权

评论回复
地板
gaoyang9992006|  楼主 | 2017-6-22 16:33 | 只看该作者
另外,在\matlab*****\toolbox\matlab\demos\graf3d.m中文件,有更加详细的介绍。界面如下:

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:西安公路研究院南京院
简介:主要工作从事监控网络与通信网络设计,以及从事基于嵌入式的通信与控制设备研发。擅长单片机嵌入式系统物联网设备开发,音频功放电路开发。

1961

主题

15933

帖子

208

粉丝