MATLAB: How to convert a figure into a uifigure

app designerconversionfigureMATLABuifigure

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

Best Answer

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)
Related Question