Matlab繪製三維曲面
阿新 • • 發佈:2019-02-06
平面網格點的生成
Matlab用meshgrid函式來生成x-y平面上的小矩形頂點座標, 呼叫格式如下:
[X, Y] = meshgrid(x,y)
網格曲面
利用meshgrid生成網格點之後,可以用mesh來繪製網格曲面。
例子:
x = -8:0.5:8;
y = x;
[X, Y] = meshgrid(x, y);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
subplot(3,3,1), mesh(Z);
subplot(3,3,2), mesh(x, y, Z);
subplot(3,3,3), mesh(X, Y, Z);
subplot(3 ,3,4), meshc(Z);
subplot(3,3,5), meshc(x, y, Z);
subplot(3,3,6), meshc(X, Y, Z);
subplot(3,3,7), meshz(Z);
subplot(3,3,8), meshz(x, y, Z);
subplot(3,3,9), meshz(X, Y, Z);
實曲面
使用surf or surfl 替代mesh
例子:
x = -8:0.5:8;
y = x;
[X, Y] = meshgrid(x, y);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
subplot(2 ,3,1), surf(Z);
shading faceted;
subplot(2,3,2), surf(x, y, Z);
shading flat;
subplot(2,3,3), surf(X, Y, Z);
shading interp;
subplot(2,3,4), surfl(Z);
shading faceted;
subplot(2,3,5), surfl(x, y, Z);
shading flat;
subplot(2,3,6), surfl(X, Y, Z);
shading interp;
end