【问题标题】:"Undefined function or variable "u"." MATLAB essay“未定义的函数或变量“u”。” MATLAB论文
【发布时间】:2013-05-24 03:45:28
【问题描述】:

我有一个非常奇怪的问题,需要提交一份 matlab 论文。 我写了一个旋转 3d 矢量的函数。我称之为旋转。

rotate 得到一个向量 v、一个角度 theta、一个角度 alpha 和一个标量 r。 该函数会将向量与 Z 轴创建的角度旋转增加 theta,将其围绕 Z 轴旋转(增加它与 X 轴创建的角度),然后将其拉伸 r。

例如:

v=(0,0,1)
theta= pi/2
alpha=0
r=1
rotate(v,theta,alpha,r) will return (0,1,0).

我的问题是,每当我调用函数旋转时,我都会收到一条错误消息: ???未定义的函数或变量“u”。

==> 中的错误在 51 处旋转 x = u(1);

而且在我写的整个代码中,没有一个函数或变量叫做“u”。

这是我的代码。基本上,我将给定的向量转换为球坐标,然后添加 theta 和 alpha。我认为它应该不工作?

function [output] = rotate(v,theta,alpha,r)
if(isnumeric(v))
    [i,j]=size(v);
    if(i>j)
        for i=1:3
            sum = sum+pow(v(i,1),2);
        end
        sum=sqrt(sum);
        output(1,1)=sum*r;
        output(2,1)=acos(v(3,1)/sum)+theta;
        output(3,1)=atan(v(2,1)/v(1,1))+alpha;
        if((output(2,1)>pi)||(output(2,1)<-1*pi))
            prompt={'Invalid values for second cordinate, more than pi or less than -pi'};
            return
        end
        if((output(3,1)>2*pi)||(output(3,1)<-2*pi))
            prompt={'Invalid values for third cordinate, more than 2 pi or less than -2pi'};
            return
        end
        r=output(1,1);
        angle1=output(2,1);
        angle2=output(3,1);
        output(1,1)=r*sin(angle1)*cos(angle2);
        output(2,1)=r*sin(angle1)*sin(angle2);
        output(3,1)=r*cos(angle1);
    else
        for j=1:3
        sum=sum+pow(v(1,j),2);
        end
        sum=sqrt(sum);
        output(1,1)=sum*r;
        output(1,2)=acos(v(1,3)/sum)+theta;
        output(1,3)=atan(v(1,2/v(1,1))+alpha;
        if((output(1,2)>pi)||(output(1,2)<-1*pi))
             prompt={'Invalid values for second cordinate, more than pi or less than -pi'};
             return;
        end
        if((output(1,3)>2*pi)||(output(1,3)<-2*pi))
            prompt={'Invalid values for third cordinate, more than 2 pi or less than -2pi'};
            return
        end;
        r=output(1,1);
        angle1=output(1,2);
        angle2=output(1,3);
        output(1,1)=r*sin(angle1)*cos(angle2);
        output(1,2)=r*sin(angle1)*cos(angle2);
        output(1,3)=r*cos(angle1);
    end
else
    prompt={'not numeric'};
    return
end
end

【问题讨论】:

    标签: matlab vector rotation


    【解决方案1】:

    您不在正确的目录中,或者您的路径设置不正确。您正在运行内置的 rotate 函数,它的参数有问题。

    如果你输入edit rotate.m,你会注意到这个函数不是你的。

    正确设置路径,和/或重命名函数。

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 2013-09-27
      • 2021-11-22
      • 2012-04-15
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      相关资源
      最近更新 更多