www.gusucode.com > 概率统计实验源程序 > 概率统计实验源程序/概率统计实验源程序(2007.8.9)/xiezhh1.m

    function varargout = xiezhh1(varargin)
% XIEZHH1 M-file for xiezhh1.fig
%      XIEZHH1, by itself, creates a new XIEZHH1 or raises the existing
%      singleton*.
%
%      H = XIEZHH1 returns the handle to a new XIEZHH1 or the handle to
%      the existing singleton*.
%
%      XIEZHH1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in XIEZHH1.M with the given input arguments.
%
%      XIEZHH1('Property','Value',...) creates a new XIEZHH1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before xiezhh1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to xiezhh1_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 xiezhh1

% Last Modified by GUIDE v2.5 06-Sep-2006 15:51:20

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

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

% Update handles structure
guidata(hObject, handles);

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


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

userdata=get(gcf,'userdata');
i=length(userdata)+1;
x=get(gcbo,'value');
if x>0
    userdata(i)=x;
end
set(gcf,'userdata',userdata);

pph1=findobj(gcf,'tag','popupmenu3');
udata1=get(pph1,'value');
pph2=findobj(gcf,'tag','popupmenu4');
udata2=get(pph2,'value');
edit_handle1=findobj(gcf,'tag','edit4');
n1=get(edit_handle1,'string');
n1=str2num(n1);
edit_handle2=findobj(gcf,'tag','edit5');
n2=get(edit_handle2,'string');
n2=str2num(n2);
edit_handle4=findobj(gcf,'tag','edit6');
n4=get(edit_handle4,'string');
n4=str2num(n4);
str1=strr1(udata2);
n=length(str1);

switch udata1
    case 1
        if ~isempty(n1)&~isempty(n2)&~isempty(n4)
            if round(n1)~=n1|round(n2)~=n2|round(n4)~=n4|(n1<=0|n2<0|n4<0)|n1<n2|n1<n4
                warndlg('请正确输入超几何分布的参数');
            else
                x=hygeinv(0.001,n1,n2,n4):hygeinv(0.999,n1,n2,n4);
                y=hygepdf(x,n1,n2,n4);
                if n>1
                    if rem(i,7)==0
                        stem(x,y,'fill',str1(7))                        
                    else
                        stem(x,y,'fill',str1(rem(i,7)))                        
                    end
                else
                    stem(x,y,'fill',str1)
                end
                hold on
                x=hygeinv(0.5,n1,n2,n4);
                text(x,hygepdf(x,n1,n2,n4),['N=',num2str(n1),',','M=',num2str(n2),',','n=',num2str(n4)])
                xlabel('X')
                ylabel('P(x)')
                %plot(zeros(11,1),0:0.1*max(y):max(y),':k')
            end
        else            
            warndlg('参数不能为空');
        end
        
    case 2
        if ~isempty(n1)&~isempty(n2)
            if round(n1)~=n1|n1<0|n2<=0|n2>=1
                warndlg('请正确输入二项分布的参数');
            else                
                x=binoinv(0.001,n1,n2):binoinv(0.999,n1,n2);
                y=binopdf(x,n1,n2);
                if n>1
                    if rem(i,7)==0
                        stem(x,y,'fill',str1(7))
                    else
                        stem(x,y,'fill',str1(rem(i,7)))
                    end
                else
                    stem(x,y,'fill',str1)
                end
                hold on
                x=binoinv(0.5,n1,n2);
                text(x,binopdf(x,n1,n2),['n=',num2str(n1),',','p=',num2str(n2)])
                xlabel('X')
                ylabel('P(x)')
                %plot(zeros(11,1),0:0.1*max(y):max(y),':k')                
            end
        else
            warndlg('参数不能为空');
        end
       
    case 3
        if ~isempty(n4)
            if n4<=0
                warndlg('请正确输入泊松分布的参数');
            else               
                x=poissinv(0.001,n4):poissinv(0.999,n4);
                y=poisspdf(x,n4);
                if n>1
                    if rem(i,7)==0
                        stem(x,y,'fill',str1(7))
                    else
                        stem(x,y,'fill',str1(rem(i,7)))
                    end
                else
                    stem(x,y,'fill',str1)
                end
                hold on
                x=poissinv(0.5,n4);
                text(x,poisspdf(x,n4),['\lambda=',num2str(n4)])
                xlabel('X')
                ylabel('P(x)')
                %plot(zeros(11,1),0:0.1*max(y):max(y),':k')                
            end
        else
            warndlg('参数不能为空');
        end
      
            
end
%set(edit_handle1,'string','')
%set(edit_handle2,'string','')
%set(edit_handle4,'string','')


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

userdata=get(gcf,'userdata');
i=length(userdata)+1;
x=get(gcbo,'value');
if x>0
    userdata(i)=x;
end
set(gcf,'userdata',userdata);

pph1=findobj(gcf,'tag','popupmenu3');
udata1=get(pph1,'value');
pph2=findobj(gcf,'tag','popupmenu4');
udata2=get(pph2,'value');
edit_handle1=findobj(gcf,'tag','edit4');
n1=get(edit_handle1,'string');
n1=str2num(n1);
edit_handle2=findobj(gcf,'tag','edit5');
n2=get(edit_handle2,'string');
n2=str2num(n2);
edit_handle4=findobj(gcf,'tag','edit6');
n4=get(edit_handle4,'string');
n4=str2num(n4);
str1=strr1(udata2);
n=length(str1);

switch udata1
    case 1
        if ~isempty(n1)&~isempty(n2)&~isempty(n4)
            if round(n1)~=n1|round(n2)~=n2|round(n4)~=n4|(n1<=0|n2<0|n4<0)|n1<n2|n1<n4
                warndlg('请正确输入超几何分布的参数');
            else
                x=hygeinv(0.001,n1,n2,n4):hygeinv(0.999,n1,n2,n4);
                y=hygecdf(x,n1,n2,n4);
                m=length(x);
                if n>1                    
                    if rem(i,7)==0                        
                        hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                        set(hl,'color',str1(7));
                        hold on
                        stem(x,y,'fill',str1(7))
                    else
                        hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                        set(hl,'color',str1(rem(i,7)));
                        hold on
                        stem(x,y,'fill',str1(rem(i,7)))
                    end
                else
                    hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                    set(hl,'color',str1);
                    hold on                    
                    stem(x,y,'fill',str1)
                end
                hold on
                %x=hygeinv(0.5,n1,n2,n4);
                %text(x,hygepdf(x,n1,n2,n4),['N=',num2str(n1),',','M=',num2str(n2),',','n=',num2str(n4)])
                xlabel('X')
                ylabel('F(x)')
                %plot(zeros(11,1),0:0.1*max(y):max(y),':k')
            end
        else            
            warndlg('参数不能为空');
        end
        
    case 2
        if ~isempty(n1)&~isempty(n2)
            if round(n1)~=n1|n1<0|n2<=0|n2>=1
                warndlg('请正确输入二项分布的参数');
            else                
                x=binoinv(0.001,n1,n2):binoinv(0.999,n1,n2);
                y=binocdf(x,n1,n2);
                m=length(x);
                if n>1
                    if rem(i,7)==0
                        hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                        set(hl,'color',str1(7));
                        hold on
                        stem(x,y,'fill',str1(7))
                    else
                        hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                        set(hl,'color',str1(rem(i,7)));
                        hold on
                        stem(x,y,'fill',str1(rem(i,7)))
                    end
                else
                    hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                    set(hl,'color',str1);
                    hold on 
                    stem(x,y,'fill',str1)
                end
                hold on
                %x=binoinv(0.5,n1,n2);
                %text(x,binopdf(x,n1,n2),['n=',num2str(n1),',','p=',num2str(n2)])
                xlabel('X')
                ylabel('F(x)')
                %plot(zeros(11,1),0:0.1*max(y):max(y),':k')                
            end
        else
            warndlg('参数不能为空');
        end
       
    case 3
        if ~isempty(n4)
            if n4<=0
                warndlg('请正确输入泊松分布的参数');
            else               
                x=poissinv(0.001,n4):poissinv(0.999,n4);
                y=poisscdf(x,n4);
                m=length(x);
                if n>1
                    if rem(i,7)==0
                        hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                        set(hl,'color',str1(7));
                        hold on
                        stem(x,y,'fill',str1(7))
                    else
                        hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                        set(hl,'color',str1(rem(i,7)));
                        hold on
                        stem(x,y,'fill',str1(rem(i,7)))
                    end
                else
                    hl=line([x(1:m-1);x(2:m)],[y(1:m-1);y(1:m-1)]);
                    set(hl,'color',str1);
                    hold on 
                    stem(x,y,'fill',str1)
                end
                hold on
                %x=poissinv(0.5,n4);
                %text(x,poisspdf(x,n4),['n=',num2str(n4)])
                xlabel('X')
                ylabel('F(x)')
                %plot(zeros(11,1),0:0.1*max(y):max(y),':k')                
            end
        else
            warndlg('参数不能为空');
        end
      
            
end
%set(edit_handle1,'string','')
%set(edit_handle2,'string','')
%set(edit_handle4,'string','')

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla

%edit_handle1=findobj(gcf,'tag','edit4');
%edit_handle2=findobj(gcf,'tag','edit5');
%edit_handle4=findobj(gcf,'tag','edit6');
%set(edit_handle1,'string','')
%set(edit_handle2,'string','')
%set(edit_handle4,'string','')


% --- Executes on button press in pushbutton8.
function pushbutton8_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)
close 常见离散型分布
shiyan


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


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

h=findobj(gcf,'tag','text19');
set(h,'string','泊松分布的参数');
edit_handle=findobj(gcf,'tag','edit4');
set(edit_handle,'string','');
edit2_handle=findobj(gcf,'tag','edit5');
set(edit2_handle,'string','');
edit3_handle=findobj(gcf,'tag','edit6');
set(edit3_handle,'string','');
pph=findobj(gcf,'tag','popupmenu3');
set(pph,'string','超几何分布|二项分布|泊松分布','FontSize',10)
pph=findobj(gcf,'tag','popupmenu4');
set(pph,'string','自动|蓝色|红色|黄色|绿色|品红|青色|黑色','FontSize',10)

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


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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


% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (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 popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu3


% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (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 selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (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 popupmenu4 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu4


% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (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