Problem using copyobj

I have created a GUI with 2 axes. The code I generated plots data onto both axes however what I want to do is export these 2 axes onto a new figure window. Here is the following code I am using:
h1 = handles.inplane_graph;
h2 = handles.outofplane_graph;
copyobj(h1,figure(1));
copyobj(h2,figure(2));
Both graphs are copied perfectly into new figure windows, however the position of the graphs are not centered and the graphs themselves are small (the same size as they appear in the GUI). I want the graphs to be standard size and centered. Can someone please help?

 Accepted Answer

Walter Roberson
Walter Roberson on 5 Dec 2011

0 votes

copyobj() copies everything, including the Position information. You can set() the Position after the copy.

3 Comments

John
John on 5 Dec 2011
I have tried setting a new position by opening a new figure window, putting axes on that figure, then using "get" to obtain the position of the axes set. Then I use copyobj and set the graph to the positions I obtained using the "get" object however, I couldn't even see the graph after doing so. What would you recommend? Thanks for the help!
get() the 'Units' in both cases: if you are using different Units then the positions would be very different.
You can set the axes position in normalized units:
nh1 = copyobj(h1,figure(1));
nh2 = copyobj(h2,figure(2));
set([nh1,nh2], 'Units', 'normalized', 'Position', [.2 .2 .6 .6]);
The .2 and .6 were chosen arbitrary to leave a margin of 1/10 of the figure area on all sides of the graph.
John
John on 5 Dec 2011
Thank you so much. The units were indeed what was causing the problem.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!