📄 six.m
字号:
function varargout = six(varargin)
% SIX M-file for six.fig
% SIX, by itself, creates a new SIX or raises the existing
% singleton*.
%
% H = SIX returns the handle to a new SIX or the handle to
% the existing singleton*.
%
% SIX('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIX.M with the given input arguments.
%
% SIX('Property','Value',...) creates a new SIX or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before six_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to six_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
% Edit the above text to modify the response to help six
% Last Modified by GUIDE v2.5 15-Aug-2003 04:21:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @six_OpeningFcn, ...
'gui_OutputFcn', @six_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 six is made visible.
function six_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 six (see VARARGIN)
% Choose default command line output for six
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes six wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = six_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 input_X_CreateFcn(hObject, eventdata, handles)% hObject handle to input_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'));endfunction input_X_Callback(hObject, eventdata, handles)% hObject handle to input_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 input_X as text% str2double(get(hObject,'String')) returns contents of input_X as a doubleX = str2num(get(hObject, 'String'));
data = getappdata(gcbf, 'mydata');
data.X = X;setappdata(gcbf, 'mydata', data);% --- Executes during object creation, after setting all properties.function input_Y_CreateFcn(hObject, eventdata, handles)% hObject handle to input_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'));endfunction input_Y_Callback(hObject, eventdata, handles)% hObject handle to input_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 input_Y as text% str2double(get(hObject,'String')) returns contents of input_Y as a doubleY = str2num(get(hObject, 'String'));data = getappdata(gcbf, 'mydata');
data.Y = Y;
setappdata(gcbf, 'mydata', data);
% --- Executes on button press in run.function run_Callback(hObject, eventdata, handles)% hObject handle to run (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, 'mydata');
if isfield(data,'X') & isfield(data,'Y') & isfield(data,'E')
[M,C,de_error]=lspoly(data.X,data.Y,data.E);
if de_error==1
uiwait(errordlg('多项式阶数超过10次,无继续求解意义!','错误提示')) ;
else
data.ans_M = M;
data.ans_C = C';
setappdata(gcbf, 'mydata', data);
set(handles.ans_M, 'String', num2str(data.ans_M));
set(handles.ans_C, 'String', num2str(data.ans_C));
xmin = min(data.X);
xmax = max(data.X);
d = (xmax - xmin)/100;
u = xmin:d:xmax;
n=length(u);
f=zeros(n,M+1);
for i=1:M+1
f(:,i)=u'.^(i-1);
end
p=f*C;
plot(data.X,data.Y,'.r',u,p,'b');
xlabel('x');
ylabel('f (x)');
end
else
uiwait(errordlg('输入参数不完整!','错误提示')) ;
end
% --- Executes on button press in reset.function reset_Callback(hObject, eventdata, handles)% hObject handle to reset (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)initialize_six(gcbf, handles);
% --------------------------------------------------------------------
function initialize_six(gcbf, handles)
data.X = ' ';
data.Y = ' ';
data.E = ' ';
data.ans_C = ' ';
data.ans_M = ' ';
setappdata(gcbf, 'mydata', data);
set(handles.input_X, 'String', data.X);
set(handles.input_Y, 'String', data.Y);
set(handles.input_E, 'String', data.E);
set(handles.ans_C, 'String', data.ans_C);
set(handles.ans_M, 'String', data.ans_M);
reset(gca);
cla;% --- Executes during object creation, after setting all properties.function input_E_CreateFcn(hObject, eventdata, handles)% hObject handle to input_E (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'));endfunction input_E_Callback(hObject, eventdata, handles)% hObject handle to input_E (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 input_E as text% str2double(get(hObject,'String')) returns contents of input_E as a doubleE = str2num(get(hObject, 'String'));
data = getappdata(gcbf, 'mydata');
data.E = E;
setappdata(gcbf, 'mydata', data);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -