フィルターのクリア

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

3 ビュー (過去 30 日間)
Benutzer Name
Benutzer Name 2018 年 8 月 28 日
編集済み: Joep Linssen 2018 年 8 月 28 日
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?

採用された回答

Joep Linssen
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 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by