转自:http://huzhyi21.blog.163.com/blog/static/1007396201061052214302/
%author:huzhyi,2010-07-10
Matlab中绘制网状图、曲面图:mesh 和 surf
x=linspace(-2, 2, 25); % 在x轴上取25点
y=linspace(-2, 2, 25); % 在y轴上取25点
[xx,yy]=meshgrid(x, y); % xx和yy都是21x21的矩阵
zz=xx.*exp(-xx.^2-yy.^2); % 计算函数值,zz也是21x21的矩阵
surf(xx, yy, zz); % 画出立体曲面图
colorbar; %如下图,右边那个色卡
%mesh 和 surf还有其他扩展,如surfc、surfl、meshc、meshz等。
![Matlab中绘制网格图和等高线:mesh 和 surf - Dream - 我的博客](http://img319.ph.126.net/WES-DH_nHog4IPcalUfeqg==/3834533607729313619.png)
Matlab中绘制等高线:contour
>> contour(xx,yy,zz)
>> colorbar
![Matlab中绘制网格图和等高线:mesh 和 surf - Dream - 我的博客](http://img.ph.126.net/gbR6nlUH7BixSPQyFsRtcw==/3712091992860295451.png)
网状图与等高线同时绘制:surfc
>> surfc(xx,yy,zz)
>> colorbar
![Matlab中绘制网格图和等高线:mesh 和 surf - Dream - 我的博客](http://img.ph.126.net/zBNnRrFYCEgBZ_h0071DgA==/920141698867437756.png)