4

Background

I have recently turned on the M-Lint warning 'M-Lint cannot decide whether ... is a variable or a function and assumes it is a function' as per Is it possible to set matlab to validate reachable functions before running in order to try to detect misspelled variable names.

M-Lint was renamed to code analyser in recent versions of matlab but I am using Matlab2007b.

Question

All functions seem to be generating this warning, even those in the same m-file. For example in the below code needlessDelegate generates this warning when used.

Is it possible to avoid this warning for valid functions? Or are my functions in some way incorrectly written?

function [biggest]=getBiggest(variable1, variable2)
    biggest=needlessDelegate(variable1, variable2); %<-- needlessDelegate generates warning. 'M-Lint cannot decide whether <name> is a variable or a function and assumes it is a function' 
end

function [biggest]=needlessDelegate(variable1, variable2)
    if variable1>variable2,
        biggest=variable1;
    else
        biggest=variable2;
    end
end

'M-Lint cannot decide whether 'needlessDelegate' is a variable or a function and assumes it is a function'

4

1 回答 1

2

你的函数没有写错。但是,此 MLint 检查不会按照我的想法(通过阅读您的其他问题)做您想要的。这不是一个非常有用的检查 - 这就是它默认关闭的原因。

在你的行之前考虑一下

biggest=needlessDelegate(variable1, variable2);

您可以拥有该命令load myData.mat,并且 .mat 文件可以包含一个变量needlessDelegate。因此,在运行时之前,MLint 通常无法知道什么是函数,什么是变量。

只有在调用之前定义了例外needlessDelegate,例如,如果您在您的行之前使用命令needlessDelegate = @(x,y) x+y;。然后您会看到 MLint 消息消失了。

如您所见,它通常不是一个非常有用的检查,这就是它默认关闭的原因。

也许这个例子也可以回答你的其他问题 - MATLAB 无法知道哪些东西可能是拼写错误或未定义的变量,因为你可以随时使用 'poof' 东西来存在load,这可以' t 在运行前检查。

于 2014-02-04T15:23:06.187 回答