MATLAB Answers

How to link to an existing library of functions in App Designer?

9 views (last 30 days)
Jay Lowe
Jay Lowe on 16 Jun 2016
Answered: Chris Portal on 27 Jul 2016
I'm creating a GUI that will require me to access a variety of complex functions that generate data to simulate real world readings. There are too many/complex functions for me to load all of them as private/public variables into the methods section of the .mlapp file. I've noticed that using app developer I've also been unable to use functions like '[xx,yy,zz] = meshgrid(x,y,z)'. I need to access the actual .m scripts/functions using their intended calls in order to use app developer for this project.
Example: -function I want to call --
function [fpb1,fpb2,fpb3,fpb4,phase,ampl ] = fpinpt(ts,noise)
%takes time in seconds (ts) and projected noise of instrument
%to randomly simulate findings in the field for test purposes
f1 = 0.1; %Hz
f2 = 0.2; %Hz
fpb1 = (noise*rand) - noise/2 + 0.05 * sin(2*pi*f1*ts);
fpb2 = (noise*rand) - noise/2 - 0.05 * sin(2*pi*f1*ts);
fpb3 = (noise*rand) - noise/2 - 0.08 * sin(2*pi*f2*ts+pi/8);
fpb4 = (noise*rand) - noise/2 + 0.08 * sin(2*pi*f2*ts+pi/8);
phase = (noise*rand) - noise/2 + 0.02 * sin(2*pi*f2*ts+pi/8);
ampl = (.5 + noise*rand) - noise/2 + 0.02 * sin(2*pi*f2*ts+pi/8);
I have modified some of these functions to use them in app developer successfully, but it's wildly impractical to do this every time I want a new function.
Example: -modified version of above with variables being assigned/initialed in the properties and startup sections of the .mlapp file --
function fpinpt(ts,noise)
% ACM generator
f1 = 0.1; %Hz
f2 = 0.2; %Hz
app.fpb1 = (noise*rand) - noise/2 + 0.05 * sin(2*pi*f1*ts);
app.fpb2 = (noise*rand) - noise/2 - 0.05 * sin(2*pi*f1*ts);
app.fpb3 = (noise*rand) - noise/2 - 0.08 * sin(2*pi*f2*ts+pi/8);
app.fpb4 = (noise*rand) - noise/2 + 0.08 * sin(2*pi*f2*ts+pi/8);
app.phase = (noise*rand) - noise/2 + 0.02 * sin(2*pi*f2*ts+pi/8);
app.ampl = (.5 + noise*rand) - noise/2 + 0.02 * sin(2*pi*f2*ts+pi/8);
How can I use the regular call '[a,b,c,d,e,f] = fpinpt(200,.001)' during run time in a callback function with app developer? I'd prefer to use it over GUIDE if possible.

Answers (1)

Chris Portal
Chris Portal on 27 Jul 2016
You can invoke these functions without re-writing them if you're just looking to execute them from within your App Designer app. If you're looking to store the results within you app for later use, you can do this by calling the function as follows:
[app.fpb1,app.fpb2,app.fpb3,app.fpb4,app.phase,app.ampl] = fpinpt(ts,noise)
This will allow you to store the results without having to rewrite the internals of your functions.

Community Treasure Hunt

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

Start Hunting!

Translated by