正文

MATLAB的图视化功能(三)2007-06-30 14:26:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/emath/27229.html

分享到:

1. 三维图形 (1)  plot3(三维直线函数) 以下例子用来体会plot 3的基本的绘图原理。 例:绘参数方程   x=t;y=sin(t);z=cos(t) 的空间曲线 clf t=0:0.05:100; x=t;y=sin(t);z=sin(2*t); plot3(x,y,z,'b:')     例:空间划线: clf t=0:0.1:10;x=t; y=0*ones(size(x));z=sin(t); plot3(x,y,z,'r') hold on z=0*ones(size(x)); y=sin(t); plot3(x,y,z,'g') xlabel('x');ylabel('y');zlabel('z');      (2)  三维曲面网格图 例1:划马鞍面: clf x=-4:0.5:4; y=-4:0.5:4; [U,V]=meshgrid(x,y); Z=-U.^4+V.^4-U.^2-V.^2-2*U*V; mesh(Z); xlabel('x'); ylabel('y'); zlabel('z');       注1:meshgrid的含义,绘图的基础是网格,一个二元系矩阵[(xi,yj)] hold off a=ones(9); a1=2*ones(5); a2=3*ones(2); a(3:7,3:7)=a1; a(5:6,5:6)=a2; meshc(a)     例二:peakS 函数的图形: peakS 函数的表达式            z  =  3*(1-x).^2.*exp(-(x.^2) - (y+1).^2)                - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2)                - 1/3*exp(-(x+1).^2 - y.^2) clf;[x,y,z]=peaks(20);p=peaks(20); subplot(2,2,1);mesh(x,y,z) subplot(2,2,2);meshz(y,x,z) subplot(2,2,3);meshc(p) subplot(2,2,4);waterfall(p)      注1:[x,y,z]=peaks(20):为变换角度带来方便。见二图。      p=peaks(20):默认x,y,z的顺序给p赋值。 注2:mesh;meshz;meshc;waterfall,表现上有区别。 注3:peaks 是演示函数。MATLAB中有许多不同的演示函数,与演示程序(**demo.m)结合在一起。 如          peaks        图形演示函数      banane      优化演示函数   (3)  色彩与效果 *1)mesh;SURF;SURFC, SURFL比较 :变更色调(由暖到冷,默认红到兰)的变化方向         shading :涂色方式 clf;x= -1.5:0.2:1.5;y=-1:0.2:1; [X,Y]=meshgrid(x,y); p=sqrt(4-X.^2/9-Y.^2/4); subplot(3,2,1);mesh(p)                   ;%有网格 格子图,色调方向:有上到下 subplot(3,2,2);surf(p)                   ;%默认的方向:色调方向:有上到下 subplot(3,2,3);surfc(p)                  ;%带登高线;色调方向:有上到下 subplot(3,2,4);surfl(p)                  ;%色调方向:沿y轴方向 shading interp                           ; %平滑涂色 图,无格线 subplot(3,2,5);surfl(p)     shading faceted                          ;%有网格涂色 格子图,有格线; subplot(3,2,6);surfl(p)     shading flat                             ;%有网格涂色 格子图,无格线;   *2)   SURFL的z-参数。看z-参数 的确定平滑涂色效果(定义变化方向)surfl(p,z);z=(n1,n2,n3)。            clf; x= -0.5:0.3:2.5;y=-0.5:0.3:2; [X,Y]=meshgrid(x,y); p=(4+X.^2/9+Y.^2/4);; %cm=[1 0 0;0 1 0;0 0 1]; %colormap(cm) subplot(2,2,1);surfl(p,[1,0,0]) subplot(2,2,2);surfl(p,[0,1,0]) subplot(2,2,3);surfl(p,[0,0,1]) subplot(2,2,4);surfl(p,[1,1,0])    (4)  辅助图视效果 *1)视角定义view(az,el) clf;x= -1.5:0.2:1.5;y=-1:0.2:1; [X,Y]=meshgrid(x,y); p=sqrt(4-X.^2/9-Y.^2/4); subplot(2,2,1);surfl(p);view(30,30) shading interp subplot(2,2,2);surfl(p);view(90,10) shading interp subplot(2,2,3);surfl(p);view(-10,-10) shading interp subplot(2,2,4);surfl(p);view(140,60) shading interp     *2)surfl光照模式与光照角度设置, surfl(x,y,z,d,s,k)指令中s 与k 参数 d:见(3) s:确定光照角度;z=(sx,sy,sz);默认光照角度是观察角逆时针方向45度 k::光照模式:确定强度        ka:  背景光          kd:  漫射光        ks:  定向光        spread:扩散光 例: clf;x= -1.5:0.2:1.5;y=-1:0.2:1; [X,Y]=meshgrid(x,y); Z=sqrt(4-X.^2/9-Y.^2/4); view(45,45) subplot(2,2,1);surfl(X,Y,Z, [0,45],[.1  .6  .4  10]); shading interp subplot(2,2,2);surfl(X,Y,Z, [20,45],[.3  .6  .4  10]); shading interp subplot(2,2,3);surfl(X,Y,Z, [40,45],[.6  .6  .4  10]); .3 shading interp subplot(2,2,4);surfl(X,Y,Z, [60,45],[.9  .6  .4  10]);  shading interp        *3) 图视放大  zoom on ;zoom off; zoom *鼠标点击变焦(左键放大;右键盘缩小) *鼠标拖拉变焦   t=-16:0.1:16;  x=sin(t.*10).*(t.^2);  plot(t,x,'r-')  zoom on       2. 超维图形表达 (1) 三维色彩表达(色轴;图象的色彩维) clf a=ones(20); a1=2*ones(13); a2=3*ones(7); a3=4*ones(2); a(4:16,4:16)=a1; a(7:13,7:13)=a2; a(10:11,10:11)=a3; subplot(2,1,1) meshc(a) subplot(2,1,2) pcolor(a) colorbar('horiz') colormap(hsv) % shading interp    (2) 四维色彩表达(色轴;图象的色彩维) clf  x=-5:0.1:5;  y=-5:0.25:5;  z=-5:0.25:5;  n=length(x);  [X,Y,Z]=meshgrid(x,y,z);  V=(-X.^2-Y.^2-Z.^2);  xi=[-4,-2,0,2,4]; yi=0.5;  zi=-0.5;  subplot(2,1,1); slice(x,y,z,V,xi,yi,zi);  colorbar('horiz');  view([45,45]); shading interp   xi=[0]; subplot(2,1,2); slice(x,y,z,V,xi,yi,zi); view([30,45]); shading interp         (3)色彩变换 spinmap      3. 句柄图形    

阅读(5660) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册