Matlab,使用meshgrid创建3D Plot

时间:2016-03-05 08:28:55

标签: matlab plot 3d mesh

我正在尝试制作3D情节。我试图使用xvals和yvals的值来获得Z值,但我得到两个错误。一个是说数据维度应该一致,并且它还说网格(X,Y,Z)在评估回调时有错误。有任何建议让这个情节?感谢

        xvals = 1.00:0.1:5.75;
        yvals = 2.5:0.1:12.5;
        [X,Y] = meshgrid(xvals,yvals);

        AB01 = sqrt((-21.6 - X).^2 + (-5.612 - Y).^2);
        AA0 = 22.269;
        pivotlength = sqrt(X.^2 + Y.^2);
        l = AB01-7.5;
        b = (pivotlength.^2 + AB01.^2 - AA0^2);
        ee = (2*pivotlength.*AB01); 
        bb= b/ee;
        thetalmax = acosd(bb);

        c = (pivotlength.^2 + l.^2 -AA0^2)/(2*pivotlength.*l);
        thetalmin = acosd(c);


        Z = thetalmin - thetalmax ; 

        mesh(Y,X,Z);

1 个答案:

答案 0 :(得分:0)

尺寸有问题。我想我修好了:

xvals = 1.00:0.1:5.75;
yvals = 2.5:0.1:12.5;

[X,Y] = meshgrid(xvals,yvals'); % added '

    AB01 = sqrt((-21.6 - X).^2 + (-5.612 - Y).^2);
    AA0 = 22.269;
    pivotlength = sqrt(X.^2 + Y.^2);
    l = AB01-7.5;
    b = (pivotlength.^2 + AB01.^2 - AA0^2);
    ee = (2*pivotlength.*AB01); 
    bb= b./ee; % added .
    thetalmax = acosd(bb);

    c = (pivotlength.^2 + l.^2 -AA0^2)./(2*pivotlength.*l);% added .
    thetalmin = acosd(c);


    Z = thetalmin - thetalmax ; 

    mesh(Y,X,Z);

BUT

您现在收到错误,因为Z值很复杂。但这是我认为的初始值问题