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)
Ältere Kommentare anzeigen
goatface killa
am 22 Mai 2019
Kommentiert: goatface killa
am 24 Mai 2019
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
0 Kommentare
Akzeptierte Antwort
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
am 23 Mai 2019
I've just added another way in my previous answer which does not save any file.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!