📄 zexc.m
字号:
function varargout = zexc(varargin)
% ZEXC M-file for zexc.fig
% ZEXC, by itself, creates a new ZEXC or raises the existing
% singleton*.
%
% H = ZEXC returns the handle to a new ZEXC or the handle to
% the existing singleton*.
%
% ZEXC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ZEXC.M with the given input arguments.
%
% ZEXC('Property','Value',...) creates a new ZEXC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before zexc_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to zexc_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help zexc
% Last Modified by GUIDE v2.5 18-Nov-2008 11:03:05
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zexc_OpeningFcn, ...
'gui_OutputFcn', @zexc_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
% --- Executes just before zexc is made visible.
function zexc_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 zexc (see VARARGIN)
% Choose default command line output for zexc
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zexc wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = zexc_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;
function x_Callback(hObject, eventdata, handles)
% hObject handle to x (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 x as text
% str2double(get(hObject,'String')) returns contents of x as a double
x=str2num(get(hObject,'String'));
if isnan(x)
set(hObject, 'String', 0);
errordlg('Input must be a array','Error');
end
handles.zxec.x = x;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function x_CreateFcn(hObject, eventdata, handles)
% hObject handle to x (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 on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function y_Callback(hObject, eventdata, handles)
% hObject handle to y (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 y as text
% str2double(get(hObject,'String')) returns contents of y as a double
y=str2num(get(hObject,'String'));
if isnan(y)
set(hObject, 'String', 0);
errordlg('Input must be a array','Error');
end
handles.zxec.y = y;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function y_CreateFcn(hObject, eventdata, handles)
% hObject handle to y (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 on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function a_Callback(hObject, eventdata, handles)
% hObject handle to a (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 a as text
% str2double(get(hObject,'String')) returns contents of a as a double
% --- Executes during object creation, after setting all properties.
function a_CreateFcn(hObject, eventdata, handles)
% hObject handle to a (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 on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function b_Callback(hObject, eventdata, handles)
% hObject handle to b (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 b as text
% str2double(get(hObject,'String')) returns contents of b as a double
% --- Executes during object creation, after setting all properties.
function b_CreateFcn(hObject, eventdata, handles)
% hObject handle to b (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 on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in aBtn.
function aBtn_Callback(hObject, eventdata, handles)
% hObject handle to aBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.a,'String',handles.zxec.a);
% --- Executes on button press in bBtn.
function bBtn_Callback(hObject, eventdata, handles)
% hObject handle to bBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.b,'String',handles.zxec.b);
% --- Executes on button press in plot.
function plot_Callback(hObject, eventdata, handles)
% hObject handle to plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=handles.zxec.x;
y=handles.zxec.y;
c=size(x);
n=c(2);
l=0;
m=0;
k=0;
p=0;
for i=1:n
l=l+x(i)*y(i);
m=m+x(i);
k=k+y(i);
p=p+x(i)^2;
end
a=(n*l-k*m)/(n*p-m^2);
b=(k*p-l*m)/(n*p-m^2);
Y=a*x+b;
plot(x,y,'r+',x,Y);
handles.zxec.a=a;
guidata(hObject,handles)
handles.zxec.b=b;
guidata(hObject,handles)
% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function print_Callback(hObject, eventdata, handles)
% hObject handle to print (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)
% --------------------------------------------------------------------
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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -