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 Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!