MATLAB: How to apply validation on matlab M-file

errorbox

I want to put a warning message box at the click of a close button in a matlab figure.
function closed(hObject, eventdata)
close(gcbf);
warndlg('are you sure you want to close','!! Warning !!')
%clear all;
%close;clear
end
however this warning dialog box appears when the window is closed! Where should I put this messagebox exactly!

Best Answer

Looks like you have your call to warndlg after "close(gcbf)". Try putting it above that.