Helper function app designer app argument
Show older comments
Hello
I am trying to create a helper funcrions in app designer. Firstly it says " use app as a first parameter", then it complains about "Undefined function or variable 'app'."
I don't quite understand what it supposed to mean.
I don't understand why I need to pass around app in private functions. I tried many things and read forums, but could not find anything for that.
Can anybody please help me?
I have attached the whole code and here is the peice.
Many thanks.
function result = curve_coords(~,curve_name)
switch curve_name
case 'Archimedean'
result = Archimedean_Curve(app,app.Radius.Value, app.Step.Value);
case 'Hilbert'
result = Hilbert_Curve(app);
end
end
function result = Archimedean_Curve(~,Radius,Step)
n = Radius/Step; % Calculates number of revolutions around origin the trajectory is going to make
x = sym('x'); % Declare symbolic variable
f_eq=@(x)Radius*(1-x./(2*pi*n)); % Mathematical formula of the trajectory
%% Calculation of the trajectory points coordinates practical method%%
smooth_coeff = 2500;
quality = smooth_coeff*n; % Calculates the number of points on the curve
theta_end=2*pi*n; % Theta upper limit
theta = (linspace(0,theta_end,quality))'; % Create a list of arguments theta and transposing it to column vec
rho=f_eq(theta); % Creating ponts of trajectory
[x_coord,y_coord]=pol2cart(theta,rho); % Getting Curve complex points
result=x_coord+1i*y_coord;
end
end
3 Comments
Adam
on 25 Jan 2019
App designer objects are classes. In a class function you must pass the class object as the first argument as this is what gives the scope resolution for the function call. This type of thing is hidden in languages like C++, but behind the scenes a C++ classs still has to pass the object of the class to its own functions.
A class function behaves the same as any other function with regards to scope - it can only see the variables in its scope - i.e. ones you pass in or ones you create within the function. If you don't pass in app then it can't see app.
The only exceptions are static functions which, by definition, are defined on the class, not the object and therefore do not require or use the object.
Ra Karamislo
on 26 Jan 2019
Matej Skrobot
on 8 Jan 2021
Yeah, thanks, that was a nice explanation.
Answers (0)
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!