Matlab:3D函数的2D投影

时间:2011-11-22 17:40:05

标签: matlab 3d plot projection

我有一个函数f(x,y)= Exp(-x^2-y^-2)(x^2+y^2)。我想在MATLAB中看看这个函数在x轴上的投影。

有关最佳方法的任何想法吗?

3 个答案:

答案 0 :(得分:3)

类似的东西:

xs = [];
ys = [];
zs = [];
for x = -10:0.1:10
    for y = -10:0.1:10
        xs = [xs x];
        ys = [ys y];
        z = f(x,y);
        zs = [zs z];
    end
end
figure; plot3(xs,ys,zs);  %plots the full function over both dimensions
figure; plot(xs,zs,'rx'); %plots the projection onto the x axis
figure; plot(ys,zs,'rx'); %plots the projection onto the y axis

沿着x和y在-10到10的范围内进行,但你可以相应地改变它。

答案 1 :(得分:3)

@Amro有一个很好的解决方案,但您也可以从MATLAB中央文件交换中查看Scott Hirsch的精彩shadowplot。看看:

>> f = @(x,y) exp(-x.^2 -y.^(-2)).*(x.^2+y.^2);
>> [X,Y] = meshgrid(-10:0.5:10,-10:0.5:10);
>> surf(X,Y,f(X,Y))
>> xlim([-11,11])
>> ylim([-11,11])
>> shadowplot x
>> shadowplot y

enter image description here

答案 2 :(得分:1)

您可以操纵view以查看x轴上的2D投影:

f = @(x,y) exp(-x.^2 -y.^(-2)).*(x.^2+y.^2);
[X,Y] = meshgrid(-10:0.5:10,-10:0.5:10);
surf(X,Y,f(X,Y))
view(90,0), shading interp
xlabel X, ylabel Y, zlabel Z

screenshot