access component with variable

3 ビュー (過去 30 日間)
Jonas Ström Seez
Jonas Ström Seez 2020 年 4 月 8 日
コメント済み: Jonas Ström Seez 2020 年 4 月 8 日
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
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!


Guillaume 2020 年 4 月 8 日
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
  1 件のコメント
Jonas Ström Seez
Jonas Ström Seez 2020 年 4 月 8 日
It worked! Thank you very much!


その他の回答 (0 件)


Help Center および File ExchangeStartup and Shutdown についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by