See https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html#buiwuyk-1-CloseRequestFcn for an example of prompting the user .
To save the information, you can save() or xlswrite() or whatever is appropriate for the way you want to store the information.