Unrecognized function or variable 'gca'
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fred Stanke
am 11 Jan. 2022
Kommentiert: Image Analyst
am 13 Jan. 2022
How can it happen that in a calling function "gca" works, but in the called function "gca" reports "Unrecognized function or variable 'gca'."
In the calling function, just before executing:
[Mlk_b_h,TierParms] = Fourier_SE_v15(NK_FM,To,ToolParms);
gca works.
if I dbstop on first line of Fourier_SE_v15:
K>> gca
Unrecognized function or variable 'gca'. Why did 'gca' disappear?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 13 Jan. 2022
Summarizing:
gca was being assigned to as a variable. With current versions of MATLAB, if you assign to a variable that has the same name as a function, then you can become unable to call the function, even if the assignment to the variable has not yet taken place.
1 Kommentar
Image Analyst
am 13 Jan. 2022
The same danger occurs often when people redefine path (another built-in variable).
Weitere Antworten (2)
Image Analyst
am 11 Jan. 2022
This script works fine for me
plot(1:10)
f()
function f()
fprintf('In f().\n')
gca
end
Are you sure you actually have an axes control visible?
3 Kommentare
Walter Roberson
am 12 Jan. 2022
I know of one circumstance that can lead to that kind of problem:
If you are inside a function, and the function has a matching end statement for the function declaration, and the function assigns to a variable that has the same name as another function (for example, assigns to sum or gca), but you have not yet executed the assignment (for example you might be stopped at a breakpoint), then in that case, you might not be able to use the name as a function.
For example,
function test
x = rand()
%location 1
if x < 0.5
gca = 7
end
%location 2
disp(x)
end
At location 2, asking
gca
could be either the number 7 or the call to the function, depending on the flow of control. In the last several releases, MATLAB has said that you cannot use the same name as a function and a variable, so at location 2, gca would not be permitted to refer to the function, but at the same time gca might not have been assigned to, so you might not be able to display gca as a variable. MATLAB can instead say "No such function or variable" for gca there.
Furthermore, the block assigns to the whole function: if you were to ask to gca at location 1 before the (possible) assignment to gca, then you cannot be referring to the function because MATLAB no longer allows the same name to be a function and a variable inside a function -- so you could get the same "No such" etc. at location 1 as well.
Fred Stanke
am 12 Jan. 2022
2 Kommentare
Image Analyst
am 13 Jan. 2022
Simply search for "gca = " or "gca=" or "gca(" to see if you assigned anything to gca or declared gca as a function. Should be real quick to learn that.
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

