📄 five.m
字号:
function varargout = five(varargin)
% FIVE M-file for five.fig
% FIVE, by itself, creates a new FIVE or raises the existing
% singleton*.
%
% H = FIVE returns the handle to a new FIVE or the handle to
% the existing singleton*.
%
% FIVE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FIVE.M with the given input arguments.
%
% FIVE('Property','Value',...) creates a new FIVE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before five_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to five_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 five
% Last Modified by GUIDE v2.5 14-Aug-2003 22:44:15
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @five_OpeningFcn, ...
'gui_OutputFcn', @five_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 five is made visible.
function five_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 five (see VARARGIN)
% Choose default command line output for five
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes five wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = five_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')
[P,newxy] = myline(data.X,data.Y);
data.ans_A = P(1);
data.ans_B = P(2);
data.ans_C = P(3);
data.ans_S = P(4);
data.ans_R = P(5);
data.ans_dA = P(6);
data.ans_dB = P(7);
data.ans_dC = P(8);
setappdata(gcbf, 'mydata', data);
set(handles.ans_A, 'String', num2str(data.ans_A));
set(handles.ans_B, 'String', num2str(data.ans_B));
set(handles.ans_C, 'String', num2str(data.ans_C));
set(handles.ans_S, 'String', num2str(data.ans_S));
set(handles.ans_R, 'String', num2str(data.ans_R));
set(handles.ans_dA, 'String', num2str(data.ans_dA));
set(handles.ans_dB, 'String', num2str(data.ans_dB));
set(handles.ans_dC, 'String', num2str(data.ans_dC));
xmin = min(data.X);
xmax = max(data.X);
d = (xmax - xmin)/100;
x = xmin:d:xmax;
y = P(2)*x+P(1);
plot(data.X,data.Y,'sb',newxy(1,:),newxy(2,:),'*r',x,y,'k');
xlabel('x');
ylabel('f (x)');
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_five(gcbf, handles);
% --------------------------------------------------------------------
function initialize_five(gcbf, handles)
data.X = ' ';
data.Y = ' ';
data.ans_A = ' ';
data.ans_B = ' ';
data.ans_C = ' ';
data.ans_S = ' ';
data.ans_R = ' ';
data.ans_dA = ' ';
data.ans_dB = ' ';
data.ans_dC = ' ';
setappdata(gcbf, 'mydata', data);
set(handles.input_X, 'String', data.X);
set(handles.input_Y, 'String', data.Y);
set(handles.ans_A, 'String', data.ans_A);
set(handles.ans_B, 'String', data.ans_B);
set(handles.ans_C, 'String', data.ans_C);
set(handles.ans_S, 'String', data.ans_S);
set(handles.ans_R, 'String', data.ans_R);
set(handles.ans_dA, 'String', data.ans_dA);
set(handles.ans_dB, 'String', data.ans_dB);
set(handles.ans_dC, 'String', data.ans_dC);
reset(gca);
cla;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -