Can anyone explain how can this happen?
Ältere Kommentare anzeigen
function myfunctest
subfcn_set('notafunc');
whos
which notafunc
notafunc
subfcn_set('sin');
whos
which sin
sin
end
function subfcn_set(n)
assignin('caller', n, ['I am ',n]);
end
running myfunctest in matlab gives
>> myfunctest
Name Size Bytes Class Attributes
notafunc 1x13 26 char
notafunc is a variable.
notafunc =
I am notafunc
Name Size Bytes Class Attributes
notafunc 1x13 26 char
sin 1x8 16 char
sin is a variable.
Error using sin
Not enough input arguments.
Error in myfunctest (line 13)
sin
The builtin sin function is called even when a local variable "sin" exists.
Akzeptierte Antwort
Weitere Antworten (1)
Guillaume
am 4 Apr. 2016
0 Stimmen
If you put a breakpoint on the sin line and execute it from the debugger the error does not occur, so I suspect it's a 'bug' with the Just-In-Time compiler introduced recently. I assume that when it loads the function, the JIT compiler sees that there is no sin variable created in the function so assumes that sin is a function call.
While it's a bug, it's also another reason for avoiding dynamic variable creation using eval, assignin, and their ilk.
Kategorien
Mehr zu Scope Variables and Generate Names finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!