|
%% Part1
function varargout = ex6(varargin)
%Pop-up Menu and Listbox gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ex6_OpeningFcn, ...
'gui_OutputFcn', @ex6_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
function ex6_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject; guidata(hObject, handles);
function varargout = ex6_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function province_Callback(hObject, eventdata, handles)
sel = get(hObject,'value');
stra = {'Zhengzhou','Luoyan','Kaifeng','Shangqiu'};
strb = {'Hefei','Wuhu','Bengbu','Huaibei','Xuancheng'};
switch sel
case 1
set(handles.city,'string','');
case 2
set(handles.city,'string',stra);
case 3
set(handles.city,'string',strb);
end
function province_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function city_Callback(hObject, eventdata, handles)
function city_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%%Part2
function varargout = ex7(varargin)
% Number conversion
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ex7_OpeningFcn, ...
'gui_OutputFcn', @ex7_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
function ex7_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = ex7_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function num_Callback(hObject, eventdata, handles)
function num_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes when selected object is changed in bin_dec.
function bin_dec_SelectionChangeFcn(hObject, eventdata, handles)
str = get(handles.num,'string');
switch get(hObject,'tag')
case'bin'
%decimal to binary
val = floor(str2double(str));
if (~isempty(val)) && (val>= 0)
set(handles.num,'string',dec2bin(val)); %dec2bin
else
set(handles.num,'string','wrong input!');
end
case'dec'
%binary to decimal
if all(str =='0' | str=='1') % for vector '|'
set(handles.num,'string',num2str(bin2dec(str)));
else
set(handles.num,'string','wrong input!')
end
end
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2025-1-8 12:47
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社