필터 지우기
필터 지우기

Elegant way to obtain the values of multiple button selection?

조회 수: 17 (최근 30일)
Peter
Peter 2015년 8월 6일
편집: Adam 2015년 8월 6일
My ui has 15 radio buttons and a couple of potentials values that can be selected by the users. The buttons are systematically named and numbered. Due to the fact that eval should be avoide, is there a elegant way to check for the selected buttons and obtain the values?
Thankt for your advice. Best, peter

채택된 답변

Adam
Adam 2015년 8월 6일
편집: Adam 2015년 8월 6일
You can create an array of radiobuttons at the start of UI as e.g.
hRadioButtons = [ handles.rb1, handles.rb2,...handles.rb15 ];
then
get( hRadioButtons, 'Value' )
will return a vector of all the results.
Alternatively you can create this array by searching your figure for children and check that their type is a UIControl with style 'radiobutton', but that is a little less structured and the ordering in which you get the children will depend (I think) on what order you added them in the UI).
You can also play around with syntax like
handles.( ['rb', str2double(n)] )
to access a radiobutton using a dynamic string. I have done this on occasions when I have named e.g. radio buttons with equivalent names as I have in an enumeration. It does obfuscate the access somewhat for readability and potential bug fixing, but can sometimes be neat if you get it right
  댓글 수: 1
Stephen23
Stephen23 2015년 8월 6일
편집: Stephen23 2015년 8월 6일
+1. Both get and set offer syntaxes for handling arrays of handles and multiple data values, and these are (in my experience) much faster and more convenient than multiple functions calls.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by