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

2 Ansichten (letzte 30 Tage)
Jay Lowe
Jay Lowe am 16 Jun. 2016
Beantwortet: Chris Portal am 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
%constants
f1 = 0.1; %Hz
f2 = 0.2; %Hz
%outputs
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);
end
--
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
%constants
f1 = 0.1; %Hz
f2 = 0.2; %Hz
%outputs
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);
end
--
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.

Antworten (1)

Chris Portal
Chris Portal am 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.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by