Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Questions About MENU Function

Asked by Kent on 1 May 2013

Hi there,

I am trying to create a menu and ask a question, wait for user's input and then use the input for further calculations.

I have 3 questions and each question only requires user to answer 'YES' or 'NO'. Using MATLAB's MENU function, I am able to do what I want. However, I would like to know if these 3 questions can be shown in one single window and ask for user's response instead of opening a new window after each question is answered.

Thanks, Kent

0 Comments

Kent

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson on 1 May 2013

Not using "menu". Yes using inputdlg(): see the example at http://www.mathworks.com/help/matlab/ref/inputdlg.html

Note: inputdlg() is a graphics function only, whereas menu() will use graphics if available but will use character text if graphics is not available.

0 Comments

Walter Roberson
Answer by Sean de Wolski on 2 May 2013

How about using a GUI with six radio buttons?

function choices = simpleRadioGUI
    hFig = figure('WindowStyle','modal');
      hBG = zeros(3,1);
      for ii = 1:3
          hBG(ii) = uibuttongroup;
          uicontrol('Style','radio',...
              'Units','normalized',...
              'Position',[0.1 0.1*ii+0.1 0.3 0.1],...
              'String','Yes!',...
              'Callback',[],...
              'Parent',hBG(ii),...
              'Value',true);
          uicontrol('Style','radio',...
              'Units','normalized',...
              'Position',[0.6 0.1*ii+0.1 0.3 0.1],...
              'String','No',...
              'Callback',[],...
              'Parent',hBG(ii),...
              'Value',false);
      end
      uicontrol('Style','pushbutton',...
            'Units','normalized',...
            'Position',[0.3 0.05 0.4 0.05],...
            'String','Done',...
            'Callback',@(~,~)closeIt);        
      choices = cell(3,1);
      uiwait(hFig);
      function closeIt
          fields = {'No','Yes'};
          for kk = 3:-1:1
              hC = get(hBG(kk),'Children');
              choices{kk} = fields(get(hC(2),'Value')+1);
          end
          close(hFig)
      end
  end

0 Comments

Sean de Wolski

Contact us