如何绘制在Matlab中定义的两个变量的函数
答
X, Y = meshgrid(xs, ys); % values of x and y at which we want to evaluate
Z = my_func(X,Y);
surf(X,Y,Z);
另外,如果你的函数没有矢量化,
X, Y = meshgrid(xs, ys); % values of x and y at which we want to evaluate
for x = 1:length(xs)
for y = 1:length(ys)
Z(x,y) = my_func(X(x,y), Y(x,y));
end
end
Z = my_func(X,Y);
surf(X,Y,Z);
答
ezsurf是一个简单的解决方案,或ezmesh,或ezcontour,或ezsurfc,或ezmeshc。
答
它有很多类型。
你可以去积库,并选择您的变量,然后类型,如网眼,3D,表面,...
,你可能会发现这个[情节画廊(http://www.mathworks.com/discovery/ gallery.html)有用(点击任何情节,你会看到代码来产生它)。在你的情况下,这将是[曲面图](http://www.mathworks.com/matlabcentral/fileexchange/35305-matlab-plot-gallery-surface-plot-1/content/html/Surface_Plot_1.html) – Amro 2012-07-27 00:57:34