Unrecognized function or variable 'gca'
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (2)
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 commentaires
Fred Stanke
le 12 Jan 2022
Image Analyst
le 12 Jan 2022
Can you just give me the whole script so I can try it?
Walter Roberson
le 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
le 12 Jan 2022
0 votes
2 commentaires
Image Analyst
le 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.
Fred Stanke
le 13 Jan 2022
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

