필터 지우기
필터 지우기

APP and global variables

조회 수: 2 (최근 30일)
José Barrera Alvarez
José Barrera Alvarez 2020년 5월 6일
댓글: José Barrera Alvarez 2020년 5월 7일
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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by