简体   繁体   English

在Matlab中绘制2参数函数的结果(3D图形)

[英]Plotting the result of a 2 parameter function in matlab (3D Graph)

Basically, I have a function f(X,Y) that would return one value for each X,Y that I give. 基本上,我有一个函数f(X,Y),该函数将为我给出的每个X,Y返回一个值。 Is there any function in matlab where I can pass the function f, the ranges for X,Y so that it plots a 3d graph showing the magnitude of f (along the z axis) for all values within the given range. matlab中是否有任何函数可以传递函数f(X,Y的范围),以便绘制一个3d图,显示给定范围内所有值的f(沿着z轴)的大小。

ezplot3, does this kind of, but it takes only one parameter 't'. ezplot3,执行这种操作,但是它仅使用一个参数“ t”。 I am very new to matlab and am trying my best to learn it fast, but I couldnt find much regarding this. 我对Matlab还是很陌生,我正在努力尽力快速学习它,但是对此我却找不到很多。 Any help would be appreciated 任何帮助,将不胜感激

Keep in mind, that with matlab, you're never really plotting "functions"; 请记住,使用matlab,您永远不会真正绘制“函数”; You're plotting arrays/vectors. 您正在绘制数组/向量。 So instead of trying to plot g = f(X,Y), you'll actually by plotting the vectors X, Y, and g, where X and Y are your original inputs and g is a vector containing your outputs. 因此,您实际上不必绘制g = f(X,Y),而是绘制矢量X,Y和g,其中X和Y是原始输入,而g是包含输出的矢量。

I'm having a hard time visualizing what exactly you're trying to plot but basically, you can follow any standard matlab plotting example such as: http://web.cecs.pdx.edu/~gerry/MATLAB/plotting/plotting.html 我很难想象您要绘制的内容,但是基本上,您可以遵循任何标准的matlab绘制示例,例如: http : //web.cecs.pdx.edu/~gerry/MATLAB/plotting/plotting .html

Well, this is what I was going for : http://www.mathworks.com/help/matlab/ref/ezsurf.html 好吧,这就是我要去的地方: http : //www.mathworks.com/help/matlab/ref/ezsurf.html

if i do this 如果我这样做

ezsurf('f(x,y)');

I get the 3d graph I wanted. 我得到了想要的3D图形。

Thanks anyways! 不管怎么说,多谢拉!

It does not produce a 3D plot, but I have found the 2D scatter plot useful for this kind of task before: 它不会生成3D图,但是我之前发现2D散点图对于此类任务很有用:

scatter(x, y, 5, z)

Where z is the value of the function at the point (x, y) will produce something similar to what you want. 其中z是点(x, y)处函数的值,将产生类似于您想要的值。 Its perhaps not quite as pretty as a full 3D plot but can be used to good effect. 它可能不如完整的3D图漂亮,但可以很好地使用。

See: 看到:

http://www.mathworks.com/matlabcentral/fileexchange/35287-matlab-plot-gallery-scatter-plot-2d/content/html/Scatter_Plot_2D.html http://www.mathworks.com/matlabcentral/fileexchange/35287-matlab-plot-gallery-scatter-plot-2d/content/html/Scatter_Plot_2D.html

Here is some (very ugly) code I put together to demonstrate the difference: 这是我放在一起的一些(非常丑陋的)代码来演示区别:

j=1;
y = -100:1:100;
for i = -100:1:100
    y = [y -100:1:100];
    count = 0;
    while count < 202;
        x(j) = i;
        j = j+1;
        count = count + 1;
    end
end

z = (abs(x) + abs(y));

figure(1)
scatter(x, y, 10, z)
h=colorbar;

figure(2)
ezsurf('(abs(x) + abs(y))')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM