Call an MLAPP with input argument(s)
조회 수: 40 (최근 30일)
이전 댓글 표시
Typically, in a classdef, you define input arguments in the class constructor. Within appdesigner, the class constructor is written automatically, and is locked out to prevent problems.
Has anybody found a different way to pass input arguments to an appdesigner MLAPP?
EDIT: This has been resolved with R2017b. For releases prior to R2017b, the accepted answer by Chris Portal is still the best workaround.
댓글 수: 0
채택된 답변
Chris Portal
2016년 5월 21일
A workaround for now is to create a public function in your app (use the "+ Function" in Code View and choose the "public" option) and use that to pass in any "input variables" after the app is created. For example:
hApp = myapp;
MySetupFunction(hApp, input1, input2);
It's not the proper way, but it's the closest way of working around the limitation for now.
댓글 수: 8
Adam
2017년 8월 11일
Yes, my 'setSelection' was just a place holder for whatever function you chose to add on your second app to set the selection. The expectation was you would create that as a function (with your chosen name) and then put relevant code inside it.
Kathy
2017년 8월 11일
Thanks, that makes sense. I'm fairly new to Matlab and especially App Designer so thanks for your patience, I appreciate the help!
추가 답변 (5개)
Melissa Williams
2017년 10월 16일
In R2017b, App Designer supports input arguments for apps. From the Run button in the toolstrip, select the drop down and select "Add Input Arguments. Add the variable names you wish to use. App Designer will automatically create a startup function for you if one does not exist, and update the constructor correctly. Write the code needed to process the input arguments in your startup function.
Adam
2016년 12월 16일
편집: Adam
2016년 12월 19일
This is certainly an unpleasant limitation. This is my first foray into appdesigner after being very familiar with creating programmatic GUIs using classes. The uneditable constructor and component initialisation functions will certainly take me some getting used to. In GUIDE I am used to passing input arguments in and using them to initialise sliders etc within the OpeningFcn.
My solution to the problem of not being able to pass input arguments to the constructor will likely be to create a 'named constructor' as a public static function, e.g.
methods ( Static, Access = public )
function app = create( someStuff, someOtherStuff )
app = MyApp;
app.someStuff = someStuff;
initialiseSlider( app, someOtherStuff );
end
end
and then launch the app as e.g.
MyApp.create( 7, 15 );
It still means that the app is created before you can assign any of your properties or setup slider components based on inputs, but hopefully that will not represent a problem.
I hope appdesigner evolves to allow more standard class usage though. I understand why some of the code is locked to stop people screwing up the app by adding code that doesn't make sense, but for people who know what they are doing it is frustrating to have to use workarounds in code design.
Annoyingly the 'coding alerts' equivalent of M-Lint are very simplistic too. I get an alert saying I should use 'app' as the first argument to this create function even though it is in a Static methods block!
댓글 수: 0
Terry Brennan
2017년 1월 25일
You can provide inputs through a subclass. If the app you created with AppDesigner is called myApp then create a subclass (not in AppDesigner, in an ordinary editor)
classdef myActualApp < myApp
methods % define the constructor
function mAA = myActualApp(inputs ...)
mAA = mAA@myApp; % this line is not really necessary
....
process inputs
...
end
end
end
댓글 수: 0
Krishna Chaitanya Duggineni
2016년 5월 19일
As far as I know you can't in the official editor You can probably with an external editor...not sure what happens then though if open the file again in the official editor
But, may be you can insert a function to change the data members and call it using callback function.
댓글 수: 0
Geoffrey Vincent
2017년 5월 10일
Hello, The app designer editor is locked. But you can copy-paste all the code from the mlapp in a classic .m file and run it like usual.
After this you can pass arguments through the constructor and the output method of the app class.
But if you still want to edit the GUI with the design view you cannot re-copy-paste the code inside the mlapp. So do the trick only when your GUI is close to be finish.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!