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?
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 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()
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)
In this way with little modification, you can make your own function to interact with the app components.