Is it good or bad thing to use handle() constructor on MATLAB Handle Graphics numeric handles?

조회 수: 1 (최근 30일)
Using handle() on a numeric graphics handle turns it into an object, e.g.
ax = handle(gca); % ax is a scalar object of class axes
h = plot(1:10); % h is a scalar double
lines = handle(h); % lines is a scalar graph2d.lineseries
The advantage of this form are several:
  • In both the command window and the workspace browser it is easier to see what these items are - you don't have to do get(h, 'Type')
  • The properties auto-complete, which is much easier, less memorising, less typing and fewer errors
  • You can get straight to the Property Inspector from the workspace browser
  • You avoid the need to do all this tiresome get(h, 'is it Xtick') and set(h, 'or was it xTicks') business, which makes code easier to read and write and saves on quoting strings (which always slows me down)
Having said all this I still mostly carry on with habit using set and get! The alternative is not shown in the Help, or any of the examples, or most of the entries on File Exchange. Why so? would you agree with me set and get is a pain in the butt, or am I missing something?

채택된 답변

Sean de Wolski
Sean de Wolski 2013년 1월 10일
편집: Sean de Wolski 2013년 1월 24일
Edit
I spoke with the developer who develops uicontrols etc. and he said this approach is okay and good if you're smart and careful about it.
Setting the object properties this way does not do the standard error checking so it is possible to corrupt the object. This would be one major reason to avoid it.
  댓글 수: 7
Julian
Julian 2013년 1월 22일
Thanks for your thoughts. Seems odd that Sean from TMW encourages this undocumented use, while Per councils against it! Actually I don't think it's a very new feature, and as I like it I will use it. Please Mr. Math Works do hurry up and improve the graphics in MATLAB....

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

per isakson
per isakson 2013년 1월 10일

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by