Radio button issue in App Designer
    12 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I am working in App designer and I have included a radio button group in my GUI. In that one button is automatically selected while opening it. I want nothing to be selected at the start. How can i do that? 
Thanks in advance
0 件のコメント
採用された回答
  dpb
      
      
 2025 年 8 月 5 日
        
      編集済み: dpb
      
      
 2025 年 8 月 5 日
  
      Short answer is "you can't".  One button in a uibuttongroup is always selected; MATLAB internal code will set  the next one (in added order) if the selected one is programmatically deselected.  By default the first in the group is the selected one.
Having none selected is not an allowed state in the design as implemented.
Even if you get clever and try to fool Mother MATLAB by having only one button in the group, one finds
>> hUIF=uifigure();
>> hUIRB=uiradiobutton(hUIF);
>> hUIRB.Value=0;
Error using matlab.ui.control.internal.model.AbstractMutualExclusiveComponent/set.Value (line 134)
'Value' cannot be set to false because it is the only component of class 'matlab.ui.control.RadioButton' or 'matlab.ui.control.ToggleButton' in the container. 
>> 
ADDENDUM:
And, creating the one radiobutton as above also automagically creates the uibuttongroup container, so there is no such thing as an independent radio button outside the container.
As @Image Analyst says, you will have to accept the behavior as it is to use radio buttons or select another interface scheme/control.
0 件のコメント
その他の回答 (1 件)
  Image Analyst
      
      
 2025 年 8 月 5 日
        
      編集済み: Image Analyst
      
      
 2025 年 8 月 6 日
  
      @dpb says he also tried it and you can't.  So I suggest, if you really want to do that, you use a different control such as a set of checkboxes or a multi-selection listbox.
I've also used a drop down list where the first item is "Select whatever" and then the list of option names follows below that.  Then you can check the .Value property of the list and act upon whatever is there.
selectedItemName = app.dropdown1.Value;
if contains(selectedItemName, 'Select')
    msgbox('Select a different choice!');
elseif contains(selectedItemName, 'Choice 1')
    msgbox('You chose choice1');
elseif contains(selectedItemName, 'Choice 2')
    msgbox('You chose choice 2');
end
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Graphics Object Programming についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


