handles in GUI code

1 回表示 (過去 30 日間)
Christof
Christof 2011 年 5 月 5 日
Hello, I need to run a loop in a GUI code that goes through a number of text fields tagged as instr1, instr2, instr3, ... in the GUI and edits the text something like
for i=1:n; set(handles.instr{i},'String','i'); end;
how can this be done? Thanks, Chris How can I

採用された回答

Jarrod Rivituso
Jarrod Rivituso 2011 年 5 月 5 日
A little string searching combined with some struct functions will get ya what you need
handles.instr1 = randn;
handles.instr2 = randn;
handles.instr3 = randn;
handles.sheep = randn;
handles.cat = randn;
handles.dog = randn;
fields = fieldnames(handles)
fieldMatches = strfind(fields,'instr')
fieldInd = ~cellfun(@isempty,fieldMatches)
validNames = fields(fieldInd)
for i = 1:length(validNames)
handles.(validNames{i})
end
Note the syntax
handles.('instr1')
is referred to in the documentation as dynamic field naming

その他の回答 (1 件)

Christof
Christof 2011 年 5 月 5 日
Thanks Jarrod

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by