【发布时间】:2009-03-23 14:41:22
【问题描述】:
我创建了一个类,在其中一种方法中我需要计算两点之间的距离。所以我写了一个名为“remoteness”的普通函数来为我做这件事。
编译错误:
在编译时,“远程”是 确定为一个变量,这 变量未初始化。 “remoteness”也是一个函数名 和以前版本的 MATLAB 将 已调用该函数。
但是,MATLAB 7 禁止在相同的上下文中使用相同的名称作为函数和变量。
==> TRobot>TRobot.makeVisibilityGraph 在 58 处出错 obj.visiblityGraph(k,k+1) = remoteness(:,obj.VGVertices(k),obj.VGVertices(:,k+1));
我认为名称 remoteness 可能是另一个函数的名称,但是当我将其名称更改为 kamran 时,错误仍然存在。需要注意的是,我可以在命令行中使用kamran函数(或remoteness)没有任何问题。
命令行示例:
>> kamran([0,0],[3,4])
ans = 5
kamran函数的代码在单独的m文件中。
kamran 函数代码:
function dist = kamran(v1,v2)
dist = sqrt( (v1(1) - v2(1)) ^2 + (v1(2) - v2(2)) ^2 );
kamran函数如何使用的代码示例:
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
【问题讨论】: