How do I access AppDesigner variables in a function that I write and call?

조회 수: 1 (최근 30일)
I am calling a function that I wrote from a GUI I designed with Appdesigner. I want to use many variables such as app.* in that function. I would rather not define a huge number of input variables for the function. I have used global variables in the past, use of global variables is not recommended by Matlab and teh global declaration gets a forbidding red underline. Is there an easy and compact way to access all the app.* variables functions called by the GUI designed in appdesigner?

채택된 답변

Ranjan Sonalkar
Ranjan Sonalkar 2022년 1월 27일
So, if I call the function with "app" as an argument, as if "app" is a structure, I should be able to refer to all the variables that are defined in the Appdesigner code as app.var1, app.var2.... etc within the function?
  댓글 수: 3
Ranjan Sonalkar
Ranjan Sonalkar 2022년 1월 27일
Thanks, that is easy enough for what I want to do now. But, it looks like I should understand MATLAB object better than I do now since the implication is that the structure properties are a subset of object properties, and I might want to use the full features of objects in the future.
Jon
Jon 2022년 1월 28일
You can also call any public methods of app, so if your app had a public function, myAppFun
function result = myAppFun(app,x)
...
end
then inside of your function, myFun that takes app as an argument you could call it using for example
function myFun(app,x)
y = app.myAppFun(x)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jon
Jon 2022년 1월 27일
편집: Jon 2022년 1월 27일
So I'm understanding that you have written a function and want to call it from within your appdesigner app. You then want this function to have access to the variables within the app. If so, I think you can get what you want simply by passing app as an argument to your function.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by