Why does axes() not return an Object but a graphics handle?
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Titus Edelhofer
2011년 11월 17일
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
추가 답변 (2개)
Daniel Shub
2011년 11월 17일
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
Daniel Shub
2011년 11월 18일
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/
Titus Edelhofer
2011년 11월 17일
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
Titus Edelhofer
2011년 11월 18일
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).
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!