フィルターのクリア

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

2 ビュー (過去 30 日間)
Shunchao Wu
Shunchao Wu 2011 年 11 月 17 日
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?

採用された回答

Titus Edelhofer
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 件のコメント
Titus Edelhofer
Titus Edelhofer 2011 年 11 月 17 日
In fact it is more or less the same ...
Shunchao Wu
Shunchao Wu 2011 年 11 月 17 日
Oh...
Obviously handle(x) is not a constructor for handle class.

サインインしてコメントする。

その他の回答 (2 件)

Daniel Shub
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
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/
Shunchao Wu
Shunchao Wu 2011 年 11 月 18 日
Thanks a lot :)

サインインしてコメントする。


Titus Edelhofer
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
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).
Shunchao Wu
Shunchao Wu 2011 年 11 月 18 日
Yes, I tested using fun2, and you're correct.
Thanks very much.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by