Using class object data within another function

2 vues (au cours des 30 derniers jours)
dweather
dweather le 12 Mar 2019
Commenté : dweather le 12 Mar 2019
Hello
Apologies, probably a fairly simplistic question but I can't seem to get it to work so any help appreciated.
I am using App Designer and am trying to use the value of an object defined within the app class of the GUI script as a variable in an external function I am calling:
end
% Button pushed function: Button
function Folder_creator_v3(app, event)
val = app.TestType.Value;
Folder_creator_v3();
% if val == 1;
%
% %%%
%
If I copy the full content of the "Folder_creator_v3" function into the GUI script, it is able to use the value for 'val' but if I specify it in this manner, when I call the function as an external file it says the variable is unspecified.
Could someone please let me know the correct syntax/method to allow the Value for TestType to be used as a variable in the external function?
Thanks!

Réponse acceptée

Adam
Adam le 12 Mar 2019
Modifié(e) : Adam le 12 Mar 2019
Folder_creator_v3( val );
is required to pass val in as an argument to your function, otherwise you are just calling it with no arguments and a function has a sealed workspace so that would be identical to if you called it that way from command line or literally anywhere else where val is not defined.
This is true of any function, irrespective of whether App Designer or classes are involved in any way.
  1 commentaire
dweather
dweather le 12 Mar 2019
Fantastic, thanks Adam. Works perfectly now.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by