필터 지우기
필터 지우기

Pushbutton output in Gui

조회 수: 2 (최근 30일)
Nidhi SRIVASTAVA
Nidhi SRIVASTAVA 2017년 6월 8일
댓글: Image Analyst 2020년 4월 21일
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