Pushbutton output in Gui
    3 views (last 30 days)
  
       Show older comments
    
I have 3 options in my GUI. I want as an output, the option number. Example pushbutton one is apple. If I click on Hexagonal, it should return '1'. The code below outputs 'hexagonal' but i want it to output '1'. Any lead in this direction, please?
My code currently:
function varargout = Gui1(varargin)
gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Gui1_OpeningFcn, ... 'gui_OutputFcn', @Gui1_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
handles.output = hObject;
guidata(hObject, handles);
% UIWAIT makes Gui1 wait for user response (see UIRESUME) uiwait(handles.figure1);
function varargout = Gui1_OutputFcn(hObject, eventdata, handles)
varargout{1} = hObject; varargout{2} = handles.string;
save 'guioutput' delete(hObject)
% --- Executes on button press in Hexagonal. function Hexagonal_Callback(hObject, eventdata, handles) % hObject handle to Hexagonal (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB selectedButton = get(hObject,'String') handles.string = selectedButton; n = 1; guidata(hObject, handles); uiresume(handles.figure1);
% handles structure with handles and user data (see GUIDATA)
0 Comments
Answers (1)
  Image Analyst
      
      
 on 8 Jun 2017
        
      Edited: Image Analyst
      
      
 on 8 Jun 2017
  
      How about
buttonNumber = menu('Pick one', 'Apple', 'Banana', 'Coconut');
Otherwise, use a radio button group, or a popup (drop down list).
4 Comments
  apri zulham
 on 21 Apr 2020
				I have a question, how to make output to static text and slider using one pushbutton?
  Image Analyst
      
      
 on 21 Apr 2020
				You need to make a string for the static text, and a number for the slider.  Let's say you have a number to start with.  Then in the pushbutton callback you would do
handles.slider1.Value = number;
if handles.slider1.Value > handles.slider1.Max
    handles.slider1.Max = handles.slider1.Value;
end
handles.text1.String = sprintf('%.3f', number);
Let's say your output is a string instead of a number.  In that case, in the pushbutton callback you'd do:
handles.slider1.Value = str2double(yourString);
if handles.slider1.Value > handles.slider1.Max
    handles.slider1.Max = handles.slider1.Value;
end
handles.text1.String = yourString;
See Also
Categories
				Find more on Line Plots in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

