How can I convert a figure into a uifigure?

Hello there
I am trying to load a saved figure in app designer (Axes Object). Is there a simple and easy way to do that?
Here's my example:
fig = openfig('storage/psychplot_base.fig', 'invisible');
plot(app.UIaxes, fig);
Thanks in advance
Mario

 Accepted Answer

Adam Danz
Adam Danz on 25 Nov 2019
Edited: Adam Danz on 25 Nov 2019
You can use copyobj() to copy the content on the external axis on to your UIAxis. This will not copy axis labels, titile, or legends but those items can be copied separately.
Step 1 is to open your external figure and get the axis handle. I'm assuming there is only 1 axis on the figure, otherwise this will need to be adapted to get the handle of the specific axis being copied.
fig = openfig('storage/psychplot_base.fig', 'invisible');
ax = findobj(fig,'Type','Axes'); % assuming 1 and only 1 handle is returned
Step 2 is to copy the children of the external axes to the app's UIAxes.
% Assuming app.UIAxes is the handle to your axes,
copyobj(ax.Children, app.UIAxes)
Step 3 is to delete the external figure
delete(fig)

1 Comment

Thank you very much, your solution works fine for me :)

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 25 Nov 2019

Commented:

on 26 Nov 2019

Community Treasure Hunt

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

Start Hunting!