Why do I receive a "Value must be a handle" error when I modify the "XLabel", "YLabel", "ZLabel", or "Title" property of an axes within MATLAB?
60 views (last 30 days)
Show older comments
MathWorks Support Team
on 10 Sep 2012
Edited: MathWorks Support Team
on 6 Sep 2018
When using the following command to set the "XLabel" property of the axes:
set(gca,'Xlabel','This is my label');
I receive an error message:
%BEGIN ERROR%%%
??? Error using ==> set
Value must be a handle.
%END ERROR%%%
Accepted Answer
MathWorks Support Team
on 6 Sep 2018
Each of the "XLabel", "YLabel", "ZLabel", and "Title" properties of the axes is actually a handle to a text object.
It is recommended to use the XLABEL, YLABEL, ZLABEL, and TITLE functions directly. For example
xlabel('This is my label')
However, if you are required to use the SET function, you can use the following command:
set(get(gca,'XLabel'),'String','This is my label')
For more information about these properties of axes objects, see the following link:
0 Comments
More Answers (0)
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!