函式簡介,程式示例,
函式簡介
函式功能:
在2-D、3-D繪圖時,還有個小差別:
[X,Y,Z] = meshgrid(x,y,z)等效於[Y,X,Z] = ndgrid(y,x,z)
語法格式:
[X1,X2,X3,...] = ndgrid(x1,x2,x3,...)
這裡,x1、x2、x3……分別限定了某一維的繪圖區間,結合起來就限定了繪圖區域。例如,1<=x<=3,4<=y<=10,-
1000<=z<=1000就限定了三維空間中的一個區域。
[X1,X2,...] = ndgrid(x)
相關函式:meshgrid,surf,mesh
程式示例
%% specify the domain
x = 0:0.5:2; y = 0:0.1:2;
%%
[xx, yy] = meshgrid(x, y);
zz = xx .* yy;
subplot(221); mesh(zz); xlabel('X'); ylabel('Y'); zlabel('Z');
title({'[xx, yy] = meshgrid(x, y)'; '\fontsize{16}{\color[rgb]{0, .5, .5}right}'});
%%
[xx, yy] = ndgrid(x, y);
zz = xx .* yy;
subplot(222); mesh(zz); xlabel('X'); ylabel('Y'); zlabel('Z');
title({'[xx, yy] = ndgrid(x, y)'; '\fontsize{16}{\color{red}wrong}'});
%%
[yy, xx] = meshgrid(y, x);
zz = xx .* yy;
subplot(223); mesh(zz); xlabel('X'); ylabel('Y'); zlabel('Z');
title({'[yy, xx] = meshgrid(y, x)'; '\fontsize{16}{\color{red}wrong}'});
%%
[yy, xx] = ndgrid(y, x);
zz = xx .* yy;
subplot(224); mesh(zz); xlabel('X'); ylabel('Y'); zlabel('Z');
title({'[yy, xx] = ndgrid(y, x)'; '\fontsize{16}{\color[rgb]{0, .5, .5}right}'});