Clear Filters
Clear Filters

Why does axes() not return an Object but a graphics handle?

2 views (last 30 days)
Hi, guys.
The graphics system in MATLAB puzzles me, here take axes for example.
What's the class name of axes object? Can users subclass it?
Why does axes() not return an axes object, but a handle?
Graphics handle is some like index/pointer/reference of a graphics object. For C Language, one can allocate a block of memory in a function and return the pointer. But I have not find that Matlab Language can implement such thing. If true, how does axes() allocate the memory for axes object and return a handle? I think the axes object should have disappeared when returned from axes
I think it is the function of MATLAB Software, not of the Matlab Language that makes axes object alive after returned from axes().
Any idea?

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 17 Nov 2011
Maybe I put my words differently: the handle graphic objects are not true MATLAB objects in the sense that you have some class file with methods etc. They are somewhat built into MATLAB itself. You can see some of it (try the following:
h = plot([1 3 2]);
hh = handle(h)
But looking at methods or properties will still not be the same as for "usual" objects.
Does this help?
Titus
  4 Comments
Shunchao Wu
Shunchao Wu on 17 Nov 2011
Oh...
Obviously handle(x) is not a constructor for handle class.

Sign in to comment.

More Answers (2)

Daniel Shub
Daniel Shub on 17 Nov 2011
MATLAB has some inconsistencies which stem from the fact that originally MATLAB only had one class (everything was stored in what would commonly be called a double). Graphics commands returned a handle to an underlying object (which was hidden from the user). The handle of course was a double. Then MATLAB introduced some different data classes (obvious data types like single, logical, etc) as well as things like cells, structures and function handles. Somewhere along the way MATLAB introduce OOP, and then later redesigned the OOP system. Graphics objects have yet to get the overhaul they deserve and need. There are rumors and indications in the code that this is changing and that someday we MATLAB may have graphics objects that behave like other objects.
  3 Comments
Daniel Shub
Daniel Shub on 18 Nov 2011
The official documentation:
http://www.mathworks.co.uk/help/techdoc/creating_plots/f7-20419.html
A blog by Loren about doubles being the only data type:
http://blogs.mathworks.com/loren/2010/04/01/double-or-nothing-no-joking/
Yair has a ton of stuff related to this:
http://undocumentedmatlab.com/blog/matlab-hg2/
http://undocumentedmatlab.com/blog/new-information-on-hg2/
http://undocumentedmatlab.com/blog/handle2struct-struct2handle-and-matlab-8/

Sign in to comment.


Titus Edelhofer
Titus Edelhofer on 17 Nov 2011
Hi,
with the function axes you create an object of type axes (similar to a constructor). The handle returned may be viewed as a reference to the object (you can copy the handle, clear the handle variable etc and the object remains unaffected). The axes object lives until either the figure it lives in dies, or it's deleted (delete(axes_handle)).
Titus
  13 Comments
Titus Edelhofer
Titus Edelhofer on 18 Nov 2011
Sorry, I did read wrong. As I said: from command line you will not see the inplace behaviour. It works only for a function called from within another function (in my example fun2 calling fun1).
Shunchao Wu
Shunchao Wu on 18 Nov 2011
Yes, I tested using fun2, and you're correct.
Thanks very much.

Sign in to comment.

Categories

Find more on Graphics Object Programming 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!