Can't open an object in antoher Figure in a Matlab GUI
1 view (last 30 days)
Show older comments
Hello,
In my GUI-Code I used to create an Object like "surf" an save it with
guidata(hObject,handles)
if I push a pushbutton. I also load it in the Workspace!
assignin('base','obj_sphere',handles.sphere);
It works, if I just use one figure because Matlab plots the surf only in this figure. Now I want to open the recently created and saved Object in an other figure on the GUI Surface but I don't now how to do it. I searched for hours now. I think I have to use the
set
function to do so. Can somebody explain in general how to open a saved Object from the Workspace, like a Surface, in a specific figure?
0 Comments
Accepted Answer
Joep Linssen
on 28 Aug 2018
Edited: Joep Linssen
on 28 Aug 2018
Hi,
The Surface object has a Parent property which points to the Axes object of the original figure. The key trick here is to copy the Surface graphics object and assign it a new parent; the function copyobj provides this functionality. In order to copy it to a new figure this empty figure needs an empty Axes object as well. A simple example follows:
[X, Y] = meshgrid(1:100, 1:100);
Z = rand(100,100);
oldfigh = figure; h1 = surf(X, Y, Z);
newfigh = figure;
newfigh.CurrentAxes = axes;
h2 = copyobj(h1, newfigh.CurrentAxes);
Note that this does not copy the Axes properties of the original figure (i.e. limits, view, color, etc.). If you have access to the original figure handle you can copy its Axes using the same function, which includes the Child Surface object:
clear;
[X, Y] = meshgrid(1:100, 1:100);
Z = rand(100,100);
oldfigh = figure; h1 = surf(X, Y, Z);
newfigh = figure;
copyobj(oldfigh.CurrentAxes, newfigh)
0 Comments
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!