Code for pushbutton in gui to close the .fig.

7 views (last 30 days)
Maria Pati
Maria Pati on 30 Aug 2019
Commented: Maria Pati on 2 Sep 2019
Screenshot001.jpg
I have a pushbutton in my .fig, shown above. The main purpose of this pushbutton is to close the .fig file. Can anyone help me what code to add in the callback function or createfcn, that after the button is pushed, the .fig file will close. Thanks.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function pushbutton1_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

Answers (1)

Walter Roberson
Walter Roberson on 30 Aug 2019
.fig files do not stay open if you use load() or uiimport() or openfig()
A .fig file would only stay open if you use fopen()
If you have have done an openfig then the .fig is automatically closed. What is left open is a figure object. You can close() or delete() figure objects. If you use close() then you can even close by figure Name property.
  1 Comment
Maria Pati
Maria Pati on 2 Sep 2019
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
I only add close in this function. Thanks Walter Roberson.

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!