如何绘制Matlab中定义的二元一元函数

如何绘制Matlab中定义的二元一元函数,matlab,plot,matlab-figure,Matlab,Plot,Matlab Figure,如何在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:

如何在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

它有多种类型

您可以进入plot gallery并选择变量,然后选择诸如mesh、3D、surface等类型

您可能会发现这很有用(单击任何绘图,您将看到生成它的代码)。在你的情况下,那将是一个