⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qjgj.m

📁 利用matlab编程进行参数检验
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = QJGJ(varargin)
% QJGJ M-file for QJGJ.fig
%      QJGJ, by itself, creates a new QJGJ or raises the existing
%      singleton*.
%
%      H = QJGJ returns the handle to a new QJGJ or the handle to
%      the existing singleton*.
%
%      QJGJ('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in QJGJ.M with the given input arguments.
%
%      QJGJ('Property','Value',...) creates a new QJGJ or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before QJGJ_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to QJGJ_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 QJGJ

% Last Modified by GUIDE v2.5 11-Aug-2007 10:34:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @QJGJ_OpeningFcn, ...
                   'gui_OutputFcn',  @QJGJ_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 QJGJ is made visible.
function QJGJ_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 QJGJ (see VARARGIN)

% Choose default command line output for QJGJ
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes QJGJ wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = QJGJ_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 on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- 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)
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
    case 1
        a=str2num(get(handles.edit1,'string'));   %得到用户输入的数据
        alpha=str2num(get(handles.edit5,'string'));
        [MUHAT,SIGMAHAT,MUCI,SIGMACI]=normfit(a,alpha);  %此函数对于参数mu和sigma分别在二者一个
                                                         %为待估参数和另一个为多余参数时均适用
                                                         %且多余参数已知或未知均可
        [m1 n1]=size(MUCI);  %观察MUCI的维数
        sh1=MUCI(1,1);   %得到置信区间的上限
        xi1=MUCI(2,1);   %得到置信区间的下限
        sh2=SIGMACI(1,1);
        xi2=SIGMACI(2,1);
        set(handles.edit3,'String',num2str(sh1));   %输出置信区间的上限
        set(handles.edit4,'String',num2str(xi1));  %输出置信区间的下限
        set(handles.edit9,'String',num2str(sh2));   %输出置信区间的上限
        set(handles.edit10,'String',num2str(xi2));  %输出置信区间的下限
        
    case 2
        a=str2num(get(handles.edit1,'string'));   %得到用户输入的数据
        b=str2num(get(handles.edit2,'string'));
        aj=mean(a);  %得到样本均值
        bj=mean(b);
        Sa=var(a);  %得到样本方差
        Sb=var(b);
        n1=length(a);  %得到样本容量
        n2=length(b);
        alpha=str2num(get(handles.edit5,'string'));   %给定常数alpha
        u2a=norminv(2*alpha,0,1);  %给定alpha,得到标准正态分布的双侧分位数
        Sy=sqrt(Sa/n1+Sb/n2);      %Sy为样本均值差的标注差
        S=sqrt(((n1-1)*Sa+(n2-1)*Sb)/(n1+n2-2));
        t2a=tinv(2*alpha,n1+n2-2);   %给定alpha,得到t分布的双侧分位数
        sigma=str2num(get(handles.edit6,'string'));
        sigma1=str2num(get(handles.edit7,'string'));
        sigma2=str2num(get(handles.edit8,'string'));
        if sigma~='X'   %从GUI界面的提示可知,若sigma为未知数时均规定输入'X',若已知则输入实际值,
                        %所以可判断sigma是否已知
            f0=0;
        else 
            f0=1;
        end
        if sigma1~='X'   %判断sigma1是否已知
            f1=0;
        else
            f1=1;
        end
        if sigma2~='X'   %判断sigma2是否已知
            f2=0;
        else
            f2=1;
        end
        if f1==0 & f2==0    %当sigma1及sigma2为已知时
            Sz=sqrt(sigma1^2/n1+sigma2^2/n2);  %Sz为总体均值差的标注差
            sh=aj-bj+u2a*Sz;
            xi=aj-bj-u2a*Sz;
        elseif f1==1 & f2==1 & n1>=50 & n2>=50  %当igma1与sigma2均为未知且n1与n2均不小于50时
            sh=aj-bj+u2a*Sy;
            xi=aj-bj-u2a*Sy;
        else sigma1==sigma2 & sigma1==sigma & f0==1 & f1==1 & f2==1   %当sigma1与sigma2均为未知,且sigma1^2=sigma2^2=sigma^2时
            sh=a1-b1+t2a*S*sqrt(1/n1+1/n2);
            xi=a1-b1-t2a*S*sqrt(1/n1+1/n2);
        end
        set(handles.edit3,'String',num2str(sh));   %输出置信区间的上限
        set(handles.edit4,'String',num2str(xi));  %输出置信区间的下限
    case 3
        a=str2num(get(handles.edit1,'string'));
        b=str2num(get(handles.edit2,'string'));
        aj=mean(a);  %得到样本均值
        bj=mean(b);
        Sa=var(a);  %得到样本方差
        Sb=var(b);
        n1=length(a);  %得到样本容量
        n2=length(b);
        alpha=str2num(get(handles.edit5,'string'));   %给定常数alpha
        u2a=norminv(2*alpha,0,1);  %给定alpha,得到标准正态分布的双侧分位数
        Sy=sqrt(Sa/n1+Sb/n2);      %Sy为样本均值差的标注差
        S=sqrt(((n1-1)*Sa+(n2-1)*Sb)/(n1+n2-2));
        t2a=tinv(2*alpha,n1+n2-2);
        mu1=str2num(get(handles.edit6,'string'));
        mu2=str2num(get(handles.edit7,'string'));
        if mu1~='X'    %判断mu1是否已知
            f3=0;
        else
            f3=1;
        end
        if mu2~='X'     %判断mu2是否已知
            f4=0;
        else
            f4=1;
        end
        F=finv(alpha/2,n2-1,n1-1);   %给定alpha,得到f分布的双侧分位数
        if f3==1 & f4==1
            sh=F*Sa/Sb;
            xi=Sa/Sb*F;
        else
            msgbox('Error!')
        end
        set(handles.edit3,'String',num2str(sh));   %输出置信区间的上限
        set(handles.edit4,'String',num2str(xi));  %输出置信区间的下限
end





function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -