MATLAB Answers

access component with variable

조회 수: 3(최근 30일)
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!

  댓글 수: 0

Sign in to comment.

채택된 답변

Guillaume
Guillaume 8 Apr 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

Jonas Ström Seez
Jonas Ström Seez 8 Apr 2020
It worked! Thank you very much!

Sign in to comment.

추가 답변(0개)

태그


Translated by