Search code examples
matlabmatlab-figurematlab-app-designer

How can I load and unload figures into a matlab app's axis?


I currently have a .m file that creates a ton of figures. It currently outputs those figures into a powerpoint, one slide per figure, but I would rather something more user friendly. I would like to use an app with app designer for this but I cannot figure out how to make figures appear inside of a GUI.

My goal: have a drop down on the left side of the GUI that lets you choose a figure title, and then that figure will appear in the large axes on the right side of the GUI.

The code currently closes each figure after it is saved, but that can be changed if necessary.

Can anyone help me with this? Is this even possible?


Solution

  • Not a complete answer, but some pointers on how to load created .fig files, and copy the axes to an uipanel.

    First create some figure:

    f1 = figure();
    subplot(211)
    imagesc(rand(100));
    subplot(212)
    plot(rand(100,1))
    
    saveas(f1, 'figure1.fig')
    

    And then load this figure in your GUI. A very simple example GUI:

    fig = uifigure;
    fig.Position = [100 100 800 600]
    pan1 = uipanel(fig, 'Title', 'Figure', 'Position',[0 0 600 600])
    pan2 = uipanel(fig, 'Title', 'Select Figure', 'Position',[600 0 200 600])
    
    f_new = openfig('figure1.fig', 'invisible'); % load 'invisible' so it doesn't popup
    ax_to_copy = f_new.Children;  % works even with subplots!
    
    % and copy the loaded axes to the uipanel:
    copyobj(ax_to_copy, pan1)
    

    Result:

    enter image description here enter image description here