Matlab 版 (精华区)

发信人: zjliu (秋天的萝卜), 信区: Matlab
标  题: 矩阵X的方差程序
发信站: BBS 哈工大紫丁香站 (Fri Mar 25 15:40:22 2005)

from 日月光华
%%注意换行
%求方差的程序和标准差的程序
          clear all
          close all
          clc
          [file1,path1]=uigetfile('*.*','打开数据文件');
          filename1=strcat(path1,file1);
          fid1=fopen(filename1,'r');
          prompt={'行数即样本总数','列数即因子数'};
          def={'  ', '  '};
          lineNo=1;
          dlgTitle='请输入参数,方差计算程序,吴建生';
          answer=inputdlg(prompt,dlgTitle,lineNo,def);
          answer=char(answer);
          ny=str2num(answer(1,:));
          nx=str2num(answer(2,:));
          [file2,path2]=uiputfile('*.*','请选择要保存结果的文件夹');
          filename2=strcat(path2,file2);
          fid2=fopen(filename2,'w');
          A1=fscanf(fid1,'%f');
          B1=reshape(A1,nx,ny)';
      fprintf(fid2,'###############******原始数据未经处理******##############

##\n');
           for i=1:ny
               for j=1:nx
                  fprintf(fid2,'%10.5f',B1(i,j));
               end
               fprintf(fid2,'\n');
            end
            fclose(fid1);
            B2=mean(B1);
            BB2=repmat(B2,ny,1);
            C1=B1-BB2;
            for i=1:nx
                t=C1(:,i);
                ty(1,i)=t'*t;
            end
           CC1=ty/(ny-1);
            CC2=var(B1);
            cs=CC1-CC2;
           fprintf(fid2,'###############*****方差*******################\n');

           for i=1
               for j=1:nx
                  fprintf(fid2,'%10.5f',CC1(i,j));
               end
               fprintf(fid2,'\n');
            end
            fprintf(fid2,'用命令计算的方差\n');
            fprintf(fid2,'VAR=\n');
            fprintf(fid2,'%12.5f\n',CC2);
            fclose(fid2);
--
╔═══════════════════╗
║★★★★★友谊第一  比赛第二★★★★★║
╚═══════════════════╝

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 天外飞仙]


※ 来源:·哈工大紫丁香 http://bbs.hit.edu.cn·[FROM: 202.118.229.*]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.253毫秒