Pushbutton output in Gui

1 次查看(过去 30 天)
Nidhi SRIVASTAVA
Nidhi SRIVASTAVA 2017-6-8
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)

回答(1 个)

Image Analyst
Image Analyst 2017-6-8
编辑:Image Analyst 2017-6-8
How about
buttonNumber = menu('Pick one', 'Apple', 'Banana', 'Coconut');
Otherwise, use a radio button group, or a popup (drop down list).
  4 个评论
apri zulham
apri zulham 2020-4-21
I have a question, how to make output to static text and slider using one pushbutton?
Image Analyst
Image Analyst 2020-4-21
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;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by