这个问题可以用slice命令实现:
%%%=================================%%%
clear all
[x,y,z] = meshgrid(0:.5:10,0:.5:10,0:.5:10);
c = x.^2+y.^2+z.^2;
xs = [0,2,4,6,8,10];
ys = [4];
zs = [6]; % xs,ys,zs可决定切片形式和位置,help slice可明白其具体含义
slice(x,y,z,c,xs,ys,zs)
colormap hsv
当然,只要doc surf, 就会发现,其实surf命令已经自带了颜色命令:
举一个简单例子如下(颜色向量看实际问题可以改变,以表示函数值):
%%%=================%%%
clear all
[X,Y]=meshgrid(0:.5:10);
c = rand(21);
Z=X^2-5*X.*Y+Y.^2;
surf(X,Y,Z,c);
[x,y,z] = meshgrid(-2:.2:2, -2:.25:2, -2:.16:2);
v = x .* exp(-x.^2 - y.^2 - z.^2);
slice(x,y,z,v,[-1.2 .8 2],2,[-2 -.2])
代码实例:
x=[1 2 3 4 5 6];
y=[1 2 3 4 5 6];
z=[3 5 6 7 8 9];
[x1,y1,z1]=meshgrid(x,y,z);
s=x1+y1+z1*2;
>> slice(x1,y1,z1,s,1,2,8)