Generalizing Function Calls with Property Dependence in App Designer
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
etia
el 18 de Abr. de 2023
Comentada: etia
el 19 de Abr. de 2023
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 comentarios
Respuesta aceptada
chicken vector
el 19 de Abr. de 2023
Editada: chicken vector
el 19 de Abr. de 2023
Use:
app.(prop_name).current
to use strings as class properties (or structure fields).
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!