'M-Lint cannot decide whether <name> is a variable or a function and assumes it is a function' warning generated for all functions

StackOverflow https://stackoverflow.com/questions/21554924

  •  06-10-2022
  •  | 
  •  

Domanda

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'

È stato utile?

Soluzione

Your functions are not incorrectly written. However, this MLint check is not going to do what I think (from reading your other question) you want. It's not a very useful check - that's why it's off by default.

Consider that before your line

biggest=needlessDelegate(variable1, variable2);

you could have had the command load myData.mat, and the .mat file could contain a variable needlessDelegate. So until runtime, there's no way for MLint to know in general what things are functions and what things are variables.

The exception is really only when needlessDelegate is defined prior to its call - for example if you preceded your line with the command needlessDelegate = @(x,y) x+y;. You'll see then that the MLint message disappears.

As you can see, it's not a very useful check in general, which is why it's off by default.

Perhaps this example also gives an answer to your other question too - MATLAB is not able to have any idea of which things might be misspellings, or undefined variables, as you can just 'poof' things into existence at any time using load, which can't be examined before runtime.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top