APP and global variables

3 ビュー (過去 30 日間)
José Barrera Alvarez
José Barrera Alvarez 2020 年 5 月 6 日
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 ?

回答 (1 件)

Steven Lord
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.
  1 件のコメント
José Barrera Alvarez
José Barrera Alvarez 2020 年 5 月 7 日
Thank you for your answer, but I think I need some more help.
As you mentioned in one of the options of your answer, my function can be run either with the app or indenpendently of the app.
As I understand, the point is passing a new parameter (the app handle in this case) to the function, so my function by means of it, will be able to read and/or modify the app.
I have been exploring the Matlab help without succced (may be for my poor experience in using the App Designer) in how to do so.
I will appreciated a lot, if you can outline to me an example on how to do it. Including the syntax of the app handle to be passed as a parameter, and how to use this app handle to access any app component.
Note. To avoid any misunderstanding, let me say that I'm using the App Designer (not GUIDE) under Matlab version (R2019b) Update 4.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by