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

36 views (last 30 days)
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?

Answers (2)

M
M on 22 May 2018
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 on 22 May 2018
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 Comments
sean borgsteede
sean borgsteede on 31 Jan 2019
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?

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by