Generalizing Function Calls with Property Dependence in App Designer
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have code that is formatted like below in App Designer. Properties I1, I2, and I3 are all callable from an instrument with their own method. So far I've just been repeating the same code in each button push callback, but I want to write a general function instead so I don't repeat code. The example below is a simple one for this purpose, but you could imagine how convoluted it could get for several methods. I understand why the code below doesn't work (it's calling a string, not the property). I am unclear as to how to generalize a format of a property and call it in the function. Help is appreciated.
Version 2020b. An upgrade is possible, if that assists with the solution.
%this is the start of App Designer
properties (Access = private)
I1
I2
I3
end
methods (Access = private)
function change_current(app, unit_number)
prop_name = join(["I", unit], '')
app.prop_name.current(40) %the code errors here as it should, since it's calling a string and not the property...how to do?
end
end
0 commentaires
Réponse acceptée
chicken vector
le 19 Avr 2023
Modifié(e) : chicken vector
le 19 Avr 2023
Use:
app.(prop_name).current
to use strings as class properties (or structure fields).
Plus de réponses (0)
Voir également
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!