APP and global variables
3 次查看(过去 30 天)
显示 更早的评论
I'm am designing an APP to collect all the data needed to lunch a time comsuming calculation.
The calculation is written as a function, having as input parameters those collected by the APP.
The calculation is lunched from the APP when the EXECUTE button is pushed. To do so, the function (calculation) is called from the body of the EXECUTE button callback.
So far, everything is O.K., but I would like to have some public (TBC) variables to be updated from the APP at the user´s wishes, and readable by the calculation during its execution, so the calculation could display intermediate plots.
I think that instead of using the calculation as a function (call from the callback body of the EXECUTE buttom) , if the calculation code is embebed into the EXECUTE callback then the problem is solved, because it has now visibility over public o private variables, but it is not my prefered option if other exists. Any suggestion ?
0 个评论
回答(1 个)
Steven Lord
2020-5-6
Is your calculation routine a function outside the app, a Static method of your app, or a non-Static method of your app?
If it's a non-Static method of your app at least one of the inputs to the method is the handle to the app. Via this handle it has access to the methods and properties of your app. It can query or modify the properties and invoke methods to cause the app to update itself.
If it's a function that can be run either with the app or independently of the app, can you have it accept an optional input that is the handle to the app? If so, when the function is passed the app handle (by the callback for your Execute button) it can update the app. When the function is called without receiving the app handle it skips trying to update the app.
If it's a Static method of your app, that would imply that it doesn't need or use information stored in any particular instance of your app. Based on your summary of your workflow I don't think that's the case.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!