设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1180|回复: 0

Matlab程序:二元函数空间曲面

[复制链接]

4

主题

64

金钱

84

积分

新手用户

发表于 2018-9-14 08:54:29 | 显示全部楼层 |阅读模式
  1. function h = mesh(x,y,z,c)
  2. %空间曲面图
  3. %  mesh(x,y,z)其中x,y,z为同阶矩阵,每一组对应元素代表一个网格点。
  4. %
  5. %例如 曲面 z=x.*exp(-x^2-y^2),-2<x<2,-2<y<2。
  6. %
  7. %     clear;close;xa=-2:.2:2;ya=xa;
  8. %     [x,y]=meshgrid(xa,ya);z=x.*exp(-x.^2-y.^2);
  9. %     mesh(x,y,z);%网格图
  10. %
  11. %MESH   3-D mesh surface.
  12. %   MESH(X,Y,Z,C) plots the colored parametric mesh defined by
  13. %   four matrix arguments.  The view point is specified by VIEW.
  14. %   The axis labels are determined by the range of X, Y and Z,
  15. %   or by the current setting of AXIS.  The color scaling is determined
  16. %   by the range of C, or by the current setting of CAXIS.  The scaled
  17. %   color values are used as indices into the current COLORMAP.
  18. %
  19. %   MESH(X,Y,Z) uses C = Z, so color is proportional to mesh height.
  20. %
  21. %   MESH(x,y,Z) and MESH(x,y,Z,C), with two vector arguments replacing
  22. %   the first two matrix arguments, must have length(x) = n and
  23. %   length(y) = m where [m,n] = size(Z).  In this case, the vertices
  24. %   of the mesh lines are the triples (x(j), y(i), Z(i,j)).
  25. %   Note that x corresponds to the columns of Z and y corresponds to
  26. %   the rows.
  27. %
  28. %   MESH(Z) and MESH(Z,C) use x = 1:n and y = 1:m.  In this case,
  29. %   the height, Z, is a single-valued function, defined over a
  30. %   geometrically rectangular grid.
  31. %
  32. %   MESH returns a handle to a SURFACE object.
  33. %
  34. %   AXIS, CAXIS, COLORMAP, HOLD, SHADING and VIEW set figure, axes, and
  35. %   surface properties which affect the display of the mesh.
  36. %
  37. %   See also SURF, MESHC, MESHZ, WATERFALL.

  38. %-------------------------------
  39. %   Additional details:
  40. %
  41. %   MESH sets the FaceColor property to background color and the EdgeColor
  42. %   property to 'flat'.
  43. %
  44. %   If the NextPlot axis property is REPLACE (HOLD is off), MESH resets
  45. %   all axis properties, except Position, to their default values
  46. %   and deletes all axis children (line, patch, surf, image, and
  47. %   text objects).

  48. %   Copyright (c) 1984-98 by The MathWorks, Inc.
  49. %   $Revision: 5.7 $  $Date: 1997/11/21 23:33:57 $

  50. %   J.N. Little 1-5-92
  51. %   Modified 2-3-92, LS.

  52. user_view = 0;
  53. cax = newplot;
  54. fc = get(gca,'color');
  55. if strcmp(lower(fc),'none')
  56.     fc = get(gcf,'color');
  57. end

  58. if nargin == 1
  59.     hh = surface(x,'FaceColor',fc,'EdgeColor','flat', 'FaceLighting', 'none', 'EdgeLighting', 'flat');
  60. elseif nargin == 2
  61.         if isstr(y), error('Invalid argument.'); end
  62.     [my ny] = size(y);
  63.     [mx nx] = size(x);
  64.     if mx == my & nx == ny
  65.         hh = surface(x,y,'FaceColor',fc,'EdgeColor','flat', 'FaceLighting', 'none', 'EdgeLighting', 'flat');
  66.     else
  67.         if my*ny == 2 % must be [az el]
  68.             hh = surface(x,'FaceColor',fc,'EdgeColor','flat', 'FaceLighting', 'none', 'EdgeLighting', 'flat');
  69.             set(gca,'View',y);
  70.             user_view = 1;
  71.         else
  72.             error('Invalid input arguments.');
  73.         end
  74.     end
  75. elseif nargin == 3
  76.         if isstr(y) | isstr(z), error('Invalid argument.'); end
  77.     if min(size(y)) == 1 & min(size(z)) == 1 % old style
  78.         hh = surface(x,'FaceColor',fc,'EdgeColor','flat', 'FaceLighting', 'none', 'EdgeLighting', 'flat');
  79.         set(gca,'View',y);
  80.         user_view = 1;
  81.     else
  82.         hh = surface(x,y,z,'FaceColor',fc,'EdgeColor','flat', 'FaceLighting', 'none', 'EdgeLighting', 'flat');
  83.     end
  84. elseif nargin == 4
  85.     hh = surface(x,y,z,c,'FaceColor',fc,'EdgeColor','flat', 'FaceLighting', 'none', 'EdgeLighting', 'flat');
  86. else
  87.     error('Requires 1, 2, 3, or 4 input arguments.');
  88. end
  89. if ~ishold & ~user_view
  90.     view(3); grid on
  91. end
  92. if nargout == 1
  93.     h = hh;
  94. end
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表