为什么将功能参数视为未定义变量? [英] Why is a function parameter considered an undefined variable?

查看:97
本文介绍了为什么将功能参数视为未定义变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找了一段时间,但是似乎找不到描述和回答我所遇到的问题的东西.也就是说,我有一个在ball类中定义的函数,该函数检查它和另一个球是否相交(由于球保持在相同的z平面上,并且所有球的半径都相同,所以我已将问题简化为相交的圈子).此函数如下(objother都属于ball类,并且ball类包含长度为3的位置向量):

I've been looking around for a while, but I can't seem to find something that describes and answers the problem I've been having. Namely, I have a function being defined in a ball class that checks to see if it and another ball are intersecting (due to the balls being kept on the same z-plane and the radius being the same for all of them, I've simplified the problem to that of intersecting circles). This function is as follows (where both obj and other are of the class ball, and where the ball class contains a position vector of length 3):

function intersected = ball_intersection(obj, other)
    intersected = (obj.position(1)-other.position(1))^2+(obj.position(2)-other.position(2))^2 <= (2*ball.radius)^2;
end

我收到以下错误:

Undefined variable other.

Error in ball/ball_intersection (line 29)
            intersected = (obj.position(1)-other.position(1))^2+(obj.position(2)-other.position(2))^2 <= (2*ball.radius)^2;

Error in ball/move (line 56)
                if ball_intersection(other)

Error in finalproject (line 41)
    cueball.move(0.0001, 0, 0, 9.32, 4.65, otherball);

由于某种原因,Matlab认为函数参数未定义,并且我不知道如何使它实际上已经在其中定义.

For some reason, Matlab thinks that a function parameter is undefined, and I don't know how to make it know that it is in fact defined right there.

感谢所有帮助-感谢您的阅读!

Any and all help is appreciated - thanks for reading!

推荐答案

ball_intersection必须使用两个输入参数来调用.

ball_intersection has to be called with two input arguments.

很可能您想将ball的第56行更改为if ball_intersection(obj,other)if obj.ball_intersection(other).

Most likely, you want to change line 56 of ball to if ball_intersection(obj,other), or if obj.ball_intersection(other).

这篇关于为什么将功能参数视为未定义变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆