Code for pushbutton in gui to close the .fig.

23 Ansichten (letzte 30 Tage)
Maria Pati
Maria Pati am 30 Aug. 2019
Kommentiert: Maria Pati am 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

Antworten (1)

Walter Roberson
Walter Roberson am 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 Kommentar
Maria Pati
Maria Pati am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects 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!

Translated by