Calling external functions in App Designer

513 ビュー (過去 30 日間)
Joshua Brophy
Joshua Brophy 2018 年 4 月 30 日
編集済み: Eric Sargent 2020 年 12 月 9 日
For a final project in a MATLAB class, we're required to create a modular program using App Designer to plot data points. We've written functions in the regular MATLAB Editor that authenticate a call to Twitter's Standard Search API, make the call, and deliver relevant information in variables to plot. All the code runs exactly how we want it to within the MATLAB command window. The trouble we're having is in figuring out how to call our functions within the App Designer. If I go into the "functions" tab within the code browser and try to add a new one, it doesn't let me add a function that doesn't have "app" as one of the input arguments. I heard elsewhere that it should be possible to call functions you've already written using the Editor, but it's unclear where to actually type in the call to these functions. I just want to be able to use the same output variables from the functions we've already written, and display the relevant data using tables and plots in the designer. Any advice on how to do that?

回答 (3 件)

Ameer Hamza
Ameer Hamza 2018 年 5 月 1 日
if you have some functions placed in you MATLAB path, it is not necessary to paste them in the app designer code. You can just call them like normal functions. For example I’d you have written a function myFunction In MATLAB editor. You can call it in app designer
function appDesignerFunction(app)
Output = myFunction(Input);
end
  4 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 21 日
Barreto, It means that there is also a property in your app named Euler(). It will not cause any error, but it can cause confusion when you are trying to debug.

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


Eric Sargent
Eric Sargent 2020 年 12 月 9 日
There is MATLAB documentation to help answer this:
But, to anwer your question here:
This sounds like a general MATLAB question and is not just specific to App Designer. Please see this post about how to use functions from other folders outside of you current directory. This approach will work the same with an App Designer app to call the function.
The difference is you will (probably) need to define the function outputs as properties of the app, and then reference those properties using "app.<variablename>" in other functions / callbacks within your app.
Please see my answer on this post related to referencing properties within App Designer and/or visit the relevant documentation to learn more:

SilverSurfer
SilverSurfer 2020 年 5 月 2 日
編集済み: SilverSurfer 2020 年 5 月 2 日
It is not really clear to me how to call external functions defined in .m files.
I have a function which search for some signals in an excel file. It has as output the list of signals found and as a input it has the full path of the file to read
function signals_final = findsignals(file_to_read)
In order to use it in the app designer I should define a new function using Function > Public function.
By looking at Ameer example it is possibile to declare it with a different name (appDesignerFunction). It is mandatory or can I use the same name as the .m file?. Why the first argument shall be app?
function appDesignerFunction(app)
Output = myFunction(Input);
end
Going back to my function I could write in the appdesigner
function findsignalsfunc(app)
Output = findsignals(Input);
end
Declaring in this way the designer get me two warnings
"Argument 'app' is unused. Should this method be Static?"
"The value assigned to variable 'Output' might be unused."
I have just tried to call the function without any declaration in the appdesigner and it works.

カテゴリ

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by