When I click on Exit, the figure closes as I intended. But if there are several figures and I only want to close figure f, I must write close( f ) which MATLAB does not recognize. I can solve it by making a function instead of a string like this:

What's wrong with nested the function? I cannot think of a better way to pass the handle, f. You can use userdata or appdata. GUIDE uses guidata which is a wrapper of appdata.It is possible to make the handle, f, available in the base workspace: assignin( 'base', ... )

Give the figure a good name, my_good_name, and use close( 'my_good_name' ) in the callback.

Thank you, I did not notice that callbacks are invoked from the base workspace up to now. I am novice in graphics programming but in my opinion nested functions are not desirable if for example an embedded function must be used not only within the function where we nested it, but inside an another function. Can we use it then?
So what do you recommend me:
* use nested functions
* use assignin
* use the UserData field ?
What are the advantages and/or disadvantages of the methods above?

I think close( 'my_good_name' ) is a good way to close the figure. It is simple, robust and self-documented.

There is a "design pattern" sometimes called redblue, which is based on nested functions. See: GUI Examples using Nested Functions. I found that useful and it was my first choice for several years. (Now, I wrap the handle graphic objects in user classes - however that is often over-kill.) One nice thing with nested functions is that you can create function handles and pass these around to other functions like any other variable.