MATLAB: How to close the figure contain the uifigure after the alert is closed

app designerMATLAB

I'm not sure if this only happens to me.
Anyways, I create a simple alert using uifigure:
f = uifigure;
mess = "It seems like you have not loaded the model. Please do so before process further.";
title = "Error 101";
uialert(f, mess, title);
After pressing OK, the alert would go away, but the figure that contains the alert is still there (and I have to manually close it).
Is there anyway that it would automatically be closed after the user pressing ok? It's so annoying.
figure1.JPG
figure2.JPG

Best Answer

The figure you specify does not actually contain the alert. The function only requires an input to determine where the alert box should be displayed. The code below makes sure to close the figure after the alert box is closed.
f = uifigure;
mess = "It seems like you have not loaded the model. Please do so before process further.";
title = "Error 101";
uialert(f, mess, title,'CloseFcn',@(h,e) close(f));