Effacer les filtres
Effacer les filtres

access component with variable

6 vues (au cours des 30 derniers jours)
Jonas Ström Seez
Jonas Ström Seez le 8 Avr 2020
Hi!
I am wondering if there is any good way to access component with a string variable. Let me give an example.
I got an array of strings and want to loop through them to access value of every component.
components = ["componentName1", "componentName2", "componentName3", ... ]
for i = 1:length(components)
value = app.components(1, i).Value
end
To clarify component(1, i) is a string and not an object inside of app, however the string has the name of that component.
I appreciate any help I can get!

Réponse acceptée

Guillaume
Guillaume le 8 Avr 2020
See Generate field names from variables which also applies to class properties.
for i = 1:numel(components) %prefer numel to length
value = app.(Components(i)).Value; %prefer 1D indexing with vectors
%..
end
  1 commentaire
Jonas Ström Seez
Jonas Ström Seez le 8 Avr 2020
It worked! Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by