Call an MLAPP with input argument(s)

32 ビュー (過去 30 日間)
Greg
Greg 2016 年 5 月 13 日
コメント済み: Greg 2017 年 10 月 16 日
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.

採用された回答

Chris Portal
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
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
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
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.
  1 件のコメント
Greg
Greg 2017 年 10 月 16 日
I voted for you answer, but I'd like to leave the original "Accepted Answer" for those not fortunate enough to have R2017b. That way, they can still see the workaround.

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


Adam
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!

Terry Brennan
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

Krishna Chaitanya Duggineni
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.

Geoffrey Vincent
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.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by