How do I call a function from the MATLAB Editor into AppDesigner

2 ビュー (過去 30 日間)
AJ Naik
AJ Naik 2018 年 5 月 22 日
コメント済み: sean borgsteede 2019 年 1 月 31 日
I have written a few functions in MATLAB's script Editor and I want to call these functions in AppDesigner. Is there any way of doing this without changing the internals of the functions? For example, if I'm using a plot function to plot a simple straight line graph, how can I call this function in AppDesigner?

回答 (2 件)

M
M 2018 年 5 月 22 日
I don't know exactly what you mean by "without changing the internals of the functions", but in the CodeView of AppDesigner, you can call your function in the same way as you would do it in the editor.

Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
If your function does not interact with the graphic elements of the app and just give you a non graphic output then you can simply call your function inside the App designer callback functions without any modification. For example, if you have defined a function myFunction() and it is placed in MATLAB path then you can simply call this function inside the app designer callback functions
function ButtonPushed(app, event)
output = myFunction()
end
But if your function needs to interact with the components of the app then you will need to make some modification. For example, to plot on the axes component of App Designer, you will need to call it as follows
plot(app.UIAxes, x, y) % you need to explicitly specify the axes, whereas normally it is optional.
Similarly, all function trying to modify the App designer components will need access to the app object and then they will be able to make any modification to the app component. The easiest way to do that is to add an extra input to myFunction() i.e. change the definition as
function output = myFunction(app, previous_inputs)
% old code
plot(app.UIAxes, x, y)
end
In this way with little modification, you can make your own function to interact with the app components.
  2 件のコメント
AJ Naik
AJ Naik 2018 年 5 月 22 日
Regarding the MATLAB path, I have saved my app and my external functions in separate folders on Desktop, and both folders cannot be opened at the same time to make those codes a part of the MATLAB path. Do I need my app and my functions to be in the same folder or is it not an issue?
sean borgsteede
sean borgsteede 2019 年 1 月 31 日
I too am running into this problem. I have scripts that I tend to use without the GUI and I also would like to use them in the GUI. Due to that, I have a folder of functions that need to be in my path during GUI execution. This works just great on my computer, but if I package it(exe or app), how do I ensure these external files will be in my path once the app/exe is installed?

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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by