Accessing Input Arguments in App Designer

조회 수: 6 (최근 30일)
Jim McIntyre
Jim McIntyre 2025년 6월 2일
댓글: Stephen23 2025년 6월 3일
I have a piece of code that works, but I'm not sure if this is the best way to do this.
I've written a GUI in App Designer. The GUI takes an input argument that is a data structure.
So the calling function is of the form:
myGUI(myStruct)
In App Designer I've created a property to contain the structure data, like this:
properties (Access = private)
myStruct % Structure to contain the struct data
end
The gui has a startup function called startupFcn, and I have specified the input argument there, so App Designer creates the following unchangeable lines:
% Code that executes after component creation
function startupFcn(app, myStruct)
Within that function I have inserted the line:
app.myStruct = myStruct; % Make data available to other functions
which, I believe is populating the property from the input argument. Once I did that I can query or change the values of app.myStruct in the other functions. If I remove the app.myStruct = line, the other functions will give errors when I try to access app.myStruct.
So, is this the correct way to access the input argument?
  댓글 수: 1
Stephen23
Stephen23 2025년 6월 3일
"So, is this the correct way to access the input argument?"
Yes.

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

채택된 답변

Adam Danz
Adam Danz 2025년 6월 2일
> is this the correct way to access the input argument (outside of the startup function)?
Yes.
The Startup Tasks and Input Arguments page mentions that the startup function is the function that receives the app's input arguments. You can choose what you want to do with those inputs within the startup function.
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2025년 6월 2일
편집: Cris LaPierre 2025년 6월 2일
I would direct you to the Startup Tasks and Input Arguments in App Designer doc page.
Yes, your app input arguments will appear as additional input to the StartupFcn. Define these inputs using the App Input Arguments found in the toolstrip when in Code View.
This input will only exist inside the startup function unless you save its value(s) to an app property,

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by