📄 tast1.m
字号:
function varargout = tast1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tast1_OpeningFcn, ...
'gui_OutputFcn', @tast1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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
% --- Executes just before tast1 is made visible.
function tast1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to tast1 (see VARARGIN)
% Choose default command line output for tast1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
initialize_gui(hObject, handles);
end
set(handles.axes1,'Visible','off');
set(handles.play,'Visible','off');
% UIWAIT makes tast1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tast1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function first_CreateFcn(hObject, eventdata, handles)
% hObject handle to first (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function first_Callback(hObject, eventdata, handles)
% hObject handle to first (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of first as text
% str2double(get(hObject,'String')) returns contents of first as a double
first = str2double(get(hObject, 'String'));
if isnan(first)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
data = getappdata(gcbf, 'metricdata');
data.first = first;
setappdata(gcbf, 'metricdata', data);
% --- Executes during object creation, after setting all properties.
function second_CreateFcn(hObject, eventdata, handles)
% hObject handle to second (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function second_Callback(hObject, eventdata, handles)
% hObject handle to second (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of second as text
% str2double(get(hObject,'String')) returns contents of second as a double
second = str2double(get(hObject, 'String'));
if isnan(second)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
data = getappdata(gcbf, 'metricdata');
data.second = second;
setappdata(gcbf, 'metricdata', data);
% --- Executes during object creation, after setting all properties.
function result_CreateFcn(hObject, eventdata, handles)
% hObject handle to result (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function result_Callback(hObject, eventdata, handles)
% hObject handle to result (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of result as text
% str2double(get(hObject,'String')) returns contents of result as a double
% --- Executes on button press in addition.
function addition_Callback(hObject, eventdata, handles)
% hObject handle to addition (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of addition
set(handles.addition, 'Value', 1);
set(handles.subtraction, 'Value', 0);
set(handles.multiplication, 'Value', 0);
set(handles.division,'Value',0);
set(handles.result, 'Value', 0);
set(handles.text1,'String','Addend');
set(handles.text2,'String','Addend');
% --- Executes on button press in subtraction.
function subtraction_Callback(hObject, eventdata, handles)
% hObject handle to subtraction (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of subtraction
set(handles.addition, 'Value', 0);
set(handles.subtraction, 'Value', 1);
set(handles.multiplication, 'Value', 0);
set(handles.division,'Value',0);
set(handles.result, 'Value', 1);
set(handles.text1,'String','Minuend');
set(handles.text2,'String','Subtrahend');
% --- Executes on button press in multiplication.
function multiplication_Callback(hObject, eventdata, handles)
% hObject handle to multiplication (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of multiplication
set(handles.addition, 'Value', 0);
set(handles.subtraction, 'Value', 0);
set(handles.multiplication, 'Value', 1);
set(handles.division,'Value',0);
set(handles.result, 'Value', 2);
set(handles.text1,'String','Multiplicand');
set(handles.text2,'String','Multiplicand');
% --- Executes on button press in division.
function division_Callback(hObject, eventdata, handles)
% hObject handle to division (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of division
set(handles.addition, 'Value', 0);
set(handles.subtraction, 'Value', 0);
set(handles.multiplication, 'Value', 0);
set(handles.division,'Value',1);
set(handles.result, 'Value', 3);
set(handles.text1,'String','Dividend');
set(handles.text2,'String','Divisor');
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = getappdata(gcbf, 'metricdata');
temp_result=get(handles.result,'Value');
switch temp_result
case 0
result = data.first + data.second;
set(handles.result, 'String', result);
case 1
result = data.first - data.second;
set(handles.result, 'String', result);
case 2
result = data.first * data.second;
set(handles.result, 'String', result);
case 3
result = data.first / data.second;
set(handles.result, 'String', result);
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
initialize_gui(gcbf, handles);
function initialize_gui(fig_handle, handles)
data.first = 0;
data.second = 0;
setappdata(fig_handle, 'metricdata', data);
set(handles.first, 'String', data.first);
set(handles.second, 'String', data.second);
set(handles.result, 'String', 0);
set(handles.addition, 'Value', 1);
set(handles.subtraction, 'Value', 0);
set(handles.multiplication, 'Value', 0);
set(handles.division,'Value',0);
set(handles.result, 'Value', 0);
set(handles.text1,'String','Addend');
set(handles.text2,'String','Addend');
% --------------------------------------------------------------------function menu_Callback(hObject, eventdata, handles)% hObject handle to menu (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function C_Callback(hObject, eventdata, handles)% hObject handle to C (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function graphics_Callback(hObject, eventdata, handles)% hObject handle to graphics (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.text1,'Visible','off');
set(handles.text2,'Visible','off');
set(handles.first,'Visible','off');
set(handles.second,'Visible','off');
set(handles.text13,'Visible','off');
set(handles.text14,'Visible','off');
set(handles.text17,'Visible','off');
set(handles.Result,'Visible','off');
set(handles.frame2,'Visible','off');
set(handles.frame3,'Visible','off');
set(handles.frame4,'Visible','off');
set(handles.addition,'Visible','off');
set(handles.subtraction,'Visible','off');
set(handles.multiplication,'Visible','off');
set(handles.division,'Visible','off');
set(handles.pushbutton1,'Visible','off');
set(handles.pushbutton2,'Visible','off');
set(handles.result,'Visible','off');
set(handles.axes1,'Visible','on');
set(handles.play,'Visible','on');
% --------------------------------------------------------------------function close_Callback(hObject, eventdata, handles)% hObject handle to close (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)% --- Executes on button press in pushbutton8.function play_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)for k=1:16
plot(fft(eye(k+16)))
axis equal
M(k)=getframe;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -