How to copy hggroup object from one figure to the other

Hello,
I am trying to copy an hggroup object (such as text-box created in PlotEditor, ot text-arrow) from one figure to the other. It is very easy to do it just by {Ctrl+C,Ctrl+V}, but how can I do it in a script? Copyobj does not work appropriately (when I use it hggroup objects become uneditable and behave strangely in a new figure). Anybody knows the solution?
P.S. I have posted similar question previously (although probably not formulated well), but no solution was found and it seems that it was forgotten, so I repost one more time and with a better formulation of the problem.
Thank you in advance,
Dima
[Moved from comment section, Jan]
It can be illustrated as following:
1. Create two figures: h1=figure; h2=figure;
2.Create a text-box object in the first figure h1 using PlotEditor (Insert->TextBox), write something in it, select it and get its handle by hgh=gco;
3. Select the next figure h2 and find its basic invisible axes as set(0,'ShowHiddenHandles','on'); iax=findobj(gcf,'type','axes','HandleVisibility','off');
4. Then copy TextBox hggroup object hgh to that axes iax: copyobj(hgh,iax);
Then the copied textbox in the figure 2 can't be edited anymore (nor text in it changed, nor its size), as well as text become shifted in respect to the frame when you change figure size, which does not happen with the original one.

댓글 수: 7

How did you use Copyobj
copyobj(hghandle,iaxhandle), where hghandle is the handle of hggroup object, and iaxhandle is a handle of the basic invisible axes of the figure to which I want to copy.
Jan
Jan 2012년 12월 16일
편집: Jan 2012년 12월 16일
Please post a running example, which reproduce your problem. I do not see any strange behavior, when I run copyobj in all of my tests. In addition it would be helpful if you explain "behave strangely" with details. Without knowing this, it is hard to guess a solution.
@Dmytro: I've moved the important information to the question, where all required information should be found.
With "a running example" I meant apiece of code, which we can copy&paste to reproduce the observed behavior. The way you have posted the code is inconvenient to copy, such that the chance to get a useful answer is reduced.
Thank you for moving it to the question. About 'running example' I fear I cannot provide it: if I knew how to emulate the creation of TextBox objects in PlotEditor I would probably know how to effectively copy it, so this is also the question.
Did you look in the source code of the PlotEditor already?
Oh... How could I forget that I can do this??? Checked now, and found out that it just creates a new annotation object by annotation(figure_handle,'textbox',Position,...) and sets all user-modified properties. Therefore, in fact I can do the same. Although one problem remains: how can I find what annotation type is the current hggroup object (is is textbox, text arrow, ellipse etc.)?
I also wonder is there still a simpler way? E.g. when you copy axes from one figure to the other by copyobj, if you see the source code, there new axes will be created from the beginning, the same situation as with hggroup textbox.

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

답변 (2개)

Jan
Jan 2012년 12월 24일

0 개 추천

You cannot expect, that objects created by the interactive PlotEditor behave equally after they have been posted to another figure. Beside the visible objects, callbacks are created and attached to the actions of the figure. And the missing of these callbacks reproduce the observed behavior.
I suggest to use another method to insert the objects in the new figure.

댓글 수: 1

Thank you for your answer. The other methods are not always more convenient. I know that it is possible to copy such objects because you can easily do this by Ctrl+C - Ctrl+V, so there is some scheme for this implemented to MatLab. I just want to figure out this scheme.

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

Thomas
Thomas 2015년 11월 19일
편집: Walter Roberson 2015년 11월 19일
Actually, this is possible:
f1=figure;
textbox=annotation('textbox','String','Hello World');
f2=figure;
newbox=annotation(f2,'textbox')
%may want to add:'linestyle','none' and/or 'position',textbox.Position
copyobj(textbox,newbox.Parent);
%this copies it into the annotationpane for newbox
Regards

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

질문:

2012년 12월 15일

편집:

2015년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by