I have searched around for the best practice to pass an app variable back to the calling app. For example, app1 is the main app and calls app2. I can easily pass variables into app2 via h = app2(a, b) when I run it from app1. However, I would like to pass back a and b to the calling app when app2 is closed. I have been using setappdata and getappdata, but don't believe this is technically the right approach.
a = 5;
b = 10;
h = app2(a,b); % app2 modifies a and b
% at this point when app2 is closed, i want a and b returned to app1