Call an MLAPP with input argument(s)
40 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Greg
el 13 de Mayo de 2016
Comentada: Greg
el 16 de Oct. de 2017
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 comentarios
Respuesta aceptada
Chris Portal
el 21 de Mayo de 2016
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 comentarios
Adam
el 11 de Ag. de 2017
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
el 11 de Ag. de 2017
Thanks, that makes sense. I'm fairly new to Matlab and especially App Designer so thanks for your patience, I appreciate the help!
Más respuestas (5)
Melissa Williams
el 16 de Oct. de 2017
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
el 16 de Dic. de 2016
Editada: Adam
el 19 de Dic. de 2016
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 comentarios
Terry Brennan
el 25 de En. de 2017
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 comentarios
Krishna Chaitanya Duggineni
el 19 de Mayo de 2016
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 comentarios
Geoffrey Vincent
el 10 de Mayo de 2017
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 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!