Axes not reconizing figure handle
Ältere Kommentare anzeigen
So I'm trying to setup a plotting function that will not overwrite any existing plots, and to predefine the values of certain properties of interest. However, for reasons I do not understand (but I think are actually obvious), using axes seems to change how it handles the Parent argument based on what other arguments I'm passing.
Plot = figure(1);
Axis = axes(Plot);
works fine, whereas
Plot = figure(1);
Axis = axes(Plot,'Position',[0.1300 0.3300 0.7750 0.700],'XLabel','SomeText','YLabel','MoreText',...
'XLim',[0:300],'YLim',[0:100]);
throws the error:
"Error using axes
Value must be handle."
My understanding is that Plot as I've defined it is a handle, and without trying to set any axis properties axes seems to accept it as such. But if I try to set any other axis properties, suddenly axes doesn't recognize the handle?
3 Kommentare
the cyclist
am 7 Okt. 2022
As an aside to your specific question, it is bad practice to use MATLAB function names, keywords, etc as variable names, so it would be better to not use "Plot" and "Axis".
Gabriel Stanley
am 7 Okt. 2022
dpb
am 7 Okt. 2022
I would also recommend against such Long_And_Drawn_Out_VariableNamesThatAreAlsoAlmostAlikeUntil_THEVERYEND
Not only are they a lot of typing for nothing, they simply obfuscate reading code for meaning and being able to tell what is going on easily. They are far more detrimental than helpful; if comments are needed to explain something, then use then out of the way of the straight line of the code itself.
Akzeptierte Antwort
Weitere Antworten (1)
The problem seems to be specifically with the XLabel argument, and the error message is non-intuitive (at least to me).
This works:
Plot = figure(1);
Axis = axes(Plot,'Position',[0.1300 0.3300 0.7750 0.700],'XLim',[0 300],'YLim',[0 100]);
Not sure if this is a bug, or something I just don't fully understand. A work-around is to add the labels later, using the xlabel function.
2 Kommentare
Exactly.
axes('XLabel', 'SomeText')
The XLabel must be a handle of a text object. The figure handle was not the problem.
Gabriel Stanley
am 7 Okt. 2022
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects 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!


