Can't open an object in antoher Figure in a Matlab GUI
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Joep Linssen
2018-8-28
编辑:Joep Linssen
2018-8-28
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!