How do I store a figure within App Designer such that it can be replotted at will by a button press?

1 Ansicht (letzte 30 Tage)
I have a simple GUI created with App Designer (version 2018a) which calls a custom function to spawn a figure showing some data. I'd like to be able to respawn this figure at will after I've closed it.
I assigned the figure a handle in the function and successfully passed it back into the app. I then assign it to a property variable within the app for later reference. Within the same callback that calls my function, the app is able to replot my figure using both the handle passed back as well as with the property variable. However, in the callback for my "Replot" button, the property value has reverted to a blank state. Is there a (succinct) way to preserve figure objects through multiple callbacks in App Designer?
sample code:
start 1st button push callback
[orig_fig1]=my_func(data); %Creates and displays a figure
app.figurestorage=orig_fig1; %Storing the figure as a private property in the app
figure(app.figurestorage) %This successfully recreates the same figure as generated within the "my_func" function
end 1st button push callback
start 2nd button push callback
fig1=app.figurestorage;
figure(fig1)
end 2nd button push callback
I get the following error from the 2nd button push:
fig1 =
handle to deleted Figure

Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 22 Mai 2019
Bearbeitet: Kojiro Saito am 23 Mai 2019
You cannot access to a deleted figure, so how about saving it as a fig file first?
start 1st button push callback
[orig_fig1]=my_func(data); %Creates and displays a figure
app.figurestorage=orig_fig1; %Storing the figure as a private property in the app
figure(app.figurestorage) %This successfully recreates the same figure as generated within the "my_func" function
savefig('myFig.fig')
end 1st button push callback
start 2nd button push callback
openfig('myFig.fig')
end 2nd button push callback
UPDATED
Here is a way without creating any file.
start 1st button push callback
[orig_fig1]=my_func(data); %Creates and displays a figure
app.figurestorage=orig_fig1; %Storing the figure as a private property in the app
figure(app.figurestorage) %This successfully recreates the same figure as generated within the "my_func" function
% Change close behavior from deleting a figure to makiig it invisible
set(app.figurestorage, 'CloseRequestFcn', {@myCloseFcn, app});
% Local function definition
function myCloseFcn(src, eve, app)
app.figurestorage.Visible = 'off';
end
end 1st button push callback
start 2nd button push callback
figure(app.figurestorage)
end 2nd button push callback
  3 Kommentare
Kojiro Saito
Kojiro Saito am 23 Mai 2019
I've just added another way in my previous answer which does not save any file.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by