The problem here is that handles is a struct and is copied by value, not updated by reference. Whenever you access handles you basically take a time-stamped version of it.
In Calculate_Callback you get the handles struct passed into your function. You then call your user function (by the way, don't pass handles or eventdata to this if you are doing it your way, it just adds confusion) and put those handles back into the GUI.
However, when your code flow returns to Calculate_Callback you then locally have the version of handles that was passed into that function still. This is no longer the up to date version that is stored in the GUI. If Calculate_Callback runs to completion without itself calling guidata( hObject, handles ) to write handles back to the GUI then you will still have the version of handles you expect stored in the actual GUI, just not in the remainder of that Calculate_Callback function.
You can do either of the following:
- Add the following line after NewValFunction(hObject, eventdata, handles) to ensure it picks up the very latest version of handles:
handles = guidata( hObject )
- Change your user function so that it takes in handles and returns handles rather than it getting and setting handles from hObject - i.e.
function handles = NewValFunction( handles )
handles.NewValue = 2;
handles
Generally I take the 2nd approach because it is simpler though I do not like it much either so in more recent GUIs I have been delegated almost everything to a class that controls things rather than the handles structure.
The 1st approach is ugly too though is it relies on your code knowing what the user function is doing and that it has to update its handles after calling it. This I have done on odd occasions too, but usually when I have complicated callback-listener setups that are editing the handles structure before code returns to my original callback function.