MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   为什么MATLAB报告我的变量未初始化? (https://www.labfans.com/bbs/showthread.php?t=22624)

poster 2019-12-10 16:49

为什么MATLAB报告我的变量未初始化?
 
我做了一个类,用它的一种方法来计算两点之间的距离。因此,我编写了一个名为“ remoteness”的普通函数来为我执行此操作。

[B]编译错误: [/B]
[INDENT]在编译时,“远程性”被确定为一个变量,并且该变量未初始化。 “ remoteness”也是函数名称,而以前的MATLAB版本会调用该函数。

[/INDENT]但是,MATLAB 7禁止在相同的上下文中使用与函数和变量相同的名称。
[INDENT] ==> TRobot> TRobot.makeVisibilityGraph中的错误为58 obj.visiblityGraph(k,k + 1)= remoteness(:,obj.VGVertices(k),obj.VGVertices(:,k + 1));

[/INDENT]我以为remoteness名称可能是另一个函数的名称,但是当我将其名称更改为kamran ,错误仍然存在。应该注意的是,我可以在命令行中使用kamran函数(或remoteness )而没有任何问题。

[B]命令行示例: [/B]

>> kamran([0,0],[3,4]) ans = 5 kamran函数的代码在单独的m文件中。

[B] kamran函数的代码: [/B]

function dist = kamran(v1,v2) dist = sqrt( (v1(1) - v2(1)) ^2 + (v1(2) - v2(2)) ^2 ); [B]有关如何使用kamran函数的代码示例: [/B]

function obj = makeVisibilityGraph(obj) verticesNumber = 0; for num = 1: size(obj.staticObstacle,2) verticesNumber = verticesNumber + size(obj.staticObstacle(num).polygon,2); end % in the below line, 2 is for start and goal vertices obj.visibilityGraph = ones(2 + size(obj.VGVertices,2)) * Inf; for j=1 : size(obj.staticObstacle,2) index = size(obj.VGVertices,2); obj.VGVertices = [obj.VGVertices, obj.staticObstacle(j).polygon]; obj.labelVGVertices = [obj.labelVGVertices, ones(1,size(obj.staticObstacle(j).polygon,2))* j ]; for k = index+1 : (size(obj.VGVertices,2)-1) obj.visiblityGraph(k,k+1) = kamran(:,obj.VGVertices(k),obj.VGVertices(:,k+1)); end % as the first and last point of a polygon are visible to each % other, so set them visible to each other obj.visibilityGraph(index+1,size(obj.VGVertices,2)) = ... kamran( obj.VGVertices(:,index+1), obj.VGVertices(:,size(obj.VGVertices,2))); end end
回答:
您似乎正在尝试将kamran用作数组:

kamran(:,obj.VGVertices(k),obj.VGVertices(:,k+1)); 注意第一个参数“:”吗?

我敢打赌,MATLAB假定kamran(如此处所述)应为3维数组,而您尝试选择的子集包含

kamran(all-of-first-index, Nth-of-second, Mth-of-third) 卡姆兰的第二次调用看起来很正确:

kamran( obj.VGVertices(:,index+1), obj.VGVertices(:,size(obj.VGVertices,2))

[url=https://stackoverflow.com/questions/673626]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:28

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.