Borrar filtros
Borrar filtros

Can't open an object in antoher Figure in a Matlab GUI

3 visualizaciones (últimos 30 días)
Benutzer Name
Benutzer Name el 28 de Ag. de 2018
Editada: Joep Linssen el 28 de Ag. de 2018
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?

Respuesta aceptada

Joep Linssen
Joep Linssen el 28 de Ag. de 2018
Editada: Joep Linssen el 28 de Ag. de 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)

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by