setting handles for an array of pushbuttons (i.e. pushbutton(i))
7 ビュー (過去 30 日間)
古いコメントを表示
i want to set handles for an array of pushbuttons starting from pushbutton1 to pushbutton10 (i.e. pushbutton(i)), is this possible in Matlab? for example a code look like
for i=1:10
set(handles.pushbuttton(i),'String','i')
end
thanks..
3 件のコメント
Jan
2012 年 3 月 12 日
Your code sets the string of the buttons to 'i'. Your comment means, that you want to get the BackgroundColor. Both are different problems.
採用された回答
Sean de Wolski
2012 年 3 月 12 日
It doesn't work because handles.pushbutton(i) does not evaluate to handles.pushbutton1 (when i is one). To work around this with GUDIE you would either need to use dynamic field names (recommended) or eval
e.g.:
set(handles.(sprintf('pushbutton%d',1)),'String',num2str(i))
or
set(eval(eval('sprintf(''handles.pushbutton%d'',1)')),'String','i')
which is highly recommended against.
その他の回答 (2 件)
Jan
2012 年 3 月 12 日
This will get the background color of all buttons as a cell:
state.allpushbuttonBG = get([handles.pushbutton],'Backgroundcolor');
and to set it later:
set([handles.pushbutton], 'Backgroundcolor', state.allpushbuttonBG);
I cannot try it currently, perhaps you need addition curly braces:
set([handles.pushbutton], {'Backgroundcolor'}, state.allpushbuttonBG);
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!