您好,欢迎访问三七文档
当前位置:首页 > 医学/心理学 > 药学 > 数据统计分析练习与matlab程序
1.频数表和直方图:统计100名同学的身高和体重直方图身高体重身高体重身高体重身高体重身高体重17275169551696417165167471716216867165521696216865166621686516459170581656416055175671737417264168571555717664172691695817657173581685016952167721705716655161491735717576158511706316963173611645916562167531716116670166631725317360178641635716954169661786017766170561675416958173731705816065179621725016347173671655817663162521656617259177661826917575170601706216963186771746616350172591766016676167631725717758177671697216650182631766817256173591746417159175681655616965168621776418470166491717117059先把数据写入一个纯文本数据文件data.txt中,数据列之间用空格键或Tab键分割,该数据文件data.txt存放在matlab\work子目录下,在Matlab中用load命令读入数据,具体作法是:loaddata.txtloaddata.txt;high=data(:,1:2:9);high=high(:);weight=data(:,2:2:10);weight=weight(:);[n1,x1]=hist(high)%下面语句与hist命令等价%n1=[length(find(high158.1)),...%length(find(high=158.1&high161.2)),...%length(find(high=161.2&high164.5)),...%length(find(high=164.5&high167.6)),...%length(find(high=167.6&high170.7)),...%length(find(high=170.7&high173.8)),...%length(find(high=173.8&high176.9)),...%length(find(high=176.9&high180)),...%length(find(high=180&high183.1)),...%length(find(high=183.1))][n2,x2]=hist(weight)subplot(1,2,1),hist(high)subplot(1,2,2),hist(weight)2.统计下列五行字符串中字符a、g、c、t出现的频数:1.aggcacggaaaaacgggaataacggaggaggacttggcacggcattacacggagg2.cggaggacaaacgggatggcggtattggaggtggcggactgttcgggga3.gggacggatacggattctggccacggacggaaaggaggacacggcggacataca4.atggataacggaaacaaaccagacaaacttcggtagaaatacagaagctta5.cggctggcggacaacggactggcggattccaaaaacggaggaggcggacggaggc把上述五行复制到一个纯文本数据文件shuju.txt中,放在matlab\work子目录下,编写如下程序:clcfid1=fopen('shuju.txt','r');i=1;while(~feof(fid1))data=fgetl(fid1);a=length(find(data==97));b=length(find(data==99));c=length(find(data==103));d=length(find(data==116));e=length(find(data=97&data=122));f(i,:)=[abcdea+b+c+d];i=i+1;endf,he=sum(f)dlmwrite('pinshu.txt',f);dlmwrite('pinshu.txt',he,'-append');fclose(fid1);我们把统计结果最后写到一个纯文本文件pinshu.txt中,在程序中多引进了几个变量,是为了检验字符串是否只包含a、g、c、t四个字符。
本文标题:数据统计分析练习与matlab程序
链接地址:https://www.777doc.com/doc-2429722 .html