If you receive an error about closing a figure in your GUI, try revising your code to include ishandle() MATLAB built-in function to first check if the figure is currently open or not.
Error using close
Invalid figure handle.
Error in TestFigureClosing CloseB (line 16)
close(FigB)
Error while evaluating UIControl Callback.