Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 为什么MATLAB报告我的变量未初始化?

我做了一个类,用它的一种方法来计算两点之间的距离。因此,我编写了一个名为“ 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
回答:
您似乎正在尝试将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))

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 19:47


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