How to call an app design function from an external .m file
29 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have an app design application myapp.mlapp and a function myfunc.m
in the app designer myfunc is called and it should calculate something for me and then plot a dada, this plot should be drawn in an UI Axes of myapp app design but i don't know how to do this.
I tied these:
- Making an object of mlapp file and then call the axes:
app = myapp;
plt = app.UiAxes1;
plot(plt,x,y);
but this code run myapp each time and i don't want to run myapp because its open already.
2. Calling a function in myapp
i made a function called func2 in app design code view and wanted to call it and let it does the things like:
app = myapp;
app.func2(x,y);
but it doesn't pass the x,y to the func2 in app designer, how can i solve this?
Regards.
0 comentarios
Respuestas (1)
Cris LaPierre
el 24 de Dic. de 2018
Editada: Cris LaPierre
el 24 de Dic. de 2018
Basically, in your app, you want to create a public function (in the code browser, switch to "Functions" and click on the drop down arrow next to the green "+" and select "Public F.unction). Here's a made up example that accepts x and y as inputs and returns x.*y as an output.
methods (Access = public)
function results = signalFunc(app,x,y)
plot(app.UIAxes,x,y);
results = x.*y;
end
end
Then to call the function externally (assuming my app is saved as myApp1.mlapp), use the following code
x = 0:.01:2*pi;
y = sin(x);
a = myApp1;
b = signalFunc(a,x,y);
5 comentarios
Yogesh Yadav
el 19 de Ag. de 2019
Did you figure out how to do this without running the app again in a new window?
Cris LaPierre
el 19 de Ag. de 2019
The simplest solution would be to only run the code a=myApp1 if a does not exist. Something like this might work.
...
if ~exist('a')
a = vidStream;
end
...
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!