1 / 26

MATLAB 实例讲座

MATLAB 实例讲座. 数据分析和统计. 所有程序都在 MATLAB V6.5 中通过测试. 数据分析和统计. 在本章中将介绍 M AT L A B 对数据处理和统计分析的命令。如果没有特别强调,本章中的 A 和 B 是指 m × n × . . . × p 的多维矩阵, x 是一个向量。. ¥.1最大值和最小值. 数据分析和统计. 例1.创建一个三维矩阵 A :. >> A(:,:,1)=[1 2 3 ;2 3 1; 3 2 1]; >> A(:,:,2)=[2 4 6 ;4 6 2; 6 4 2];

farrah
Download Presentation

MATLAB 实例讲座

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB实例讲座 数据分析和统计 所有程序都在MATLAB V6.5中通过测试

  2. 数据分析和统计 在本章中将介绍M AT L A B对数据处理和统计分析的命令。如果没有特别强调,本章中的A和B是指m×n×. . .×p的多维矩阵,x是一个向量。 ¥.1最大值和最小值

  3. 数据分析和统计 例1.创建一个三维矩阵A: >> A(:,:,1)=[1 2 3;2 3 1; 3 2 1]; >> A(:,:,2)=[2 4 6;4 6 2;6 4 2]; >> max(A) ans(:,:,1) = 3 3 3 ans(:,:,2) = 6 6 6 >> whos Name Size Bytes Class A 3x3x2 144 double array ans 1x3x2 48 double array Grand total is 24 elements using 192 bytes

  4. 数据分析和统计 求和、乘积和差分 求和 对例 . 1中的矩阵A进行求和及累计和,其操作如下: >> TheSum=sum(A), TheCsum=cumsum(A) TheSum(:,:,1) =

  5. 数据分析和统计 6 7 5 TheSum(:,:,2) = 12 14 10 TheCsum(:,:,1) = 1 2 3 3 5 4 6 7 5 TheCsum(:,:,2) = 2 4 6 6 10 8 12 14 10

  6. 数据分析和统计 乘积

  7. 数据分析和统计 差分和梯度

  8. 数据分析和统计 差分计算很容易,它还可以当作导数的近似值来用。 >> x=[1 4 9 16 25]; >> d1=diff(x),d2=diff(d1),d3=diff(d2) d1 = 3 5 7 9 d2 = 2 2 2 d3 = 0 0 统计命令 平均值、中值和标准差

  9. 数据分析和统计 >> A=[1 1;2 2;3 3;4 100]; >> average=mean(A),med=median(A),dev=std(A) average = 2.5000 26.5000 med = 2.5000 2.5000 dev = 1.2910 49.0068 协方差和相关系数

  10. 数据分析和统计 假设定义如下向量: (a) 通过下列命令来求得方差: >> x=[1 1 1];y=[1 2 2];z=[0 -1 1]; >> varx=cov(x), vary=cov(y), varz=cov(z) varx = 0 vary = 0.3333 varz =1 (b) 协方差为: >> Cvxy=cov(x,y),Cvxz=cov(x,z),Cvyz=cov(y,z) Cvxy = 0 0 0 0.3333

  11. 数据分析和统计 Cvxz = 0 0 0 1 Cvyz = 0.3333 0 0 1.0000 排序

  12. 数据分析和统计 (a) 执行命令[ A s c e n d , I n d ] = s o r t ( A ),结果为:

  13. 数据分析和统计 >> A=[0 4 4;2 0 2;4 2 0]; >> [Ascent,Ind]=sort(A) Ascent = 0 0 0 2 2 2 4 4 4 Ind = 1 2 3 2 3 2 3 1 1 [B, Ind]=sort(A) 返回矩阵I n d和矩阵B,矩阵B的列为矩阵A中按递增排序的列,矩阵I n d的每列相对应于上面提到的向量中列i n d。

  14. 数据分析和统计 统计频数直方图和棒图 使用命令h i s t、b a r和s t a i r s, 将数据集合以统计频数直方图和棒图显示出来。

  15. 数据分析和统计 图表

  16. 数据分析和统计 假设x为: >> x=[1 1 3 4 5 1 9 8]; >> hist(x);title('Histogram of x use hist')

  17. 数据分析和统计 (b) 要画出在三个区间内的统计频数直方图,可输入: >> hist(x,3); title('Histogram of x using hist(x,3)')

  18. 数据分析和统计 (c) 画棒图可以输入: >> bar(x); title('bar(x)'); 数值 次数

  19. 数据分析和统计 用命令s t e m ( x )来画出向量x的火柴杆图 如果再定义一个向量:

  20. 数据分析和统计

  21. 数据分析和统计 高级话题—应用举例 • 在这里,我们从数据库中调出三个地区的气象温度资料数据。我们试图对这些数据进行初步的分析和处理,以得到以下我们想要的图形和数据。 • 三个地区的气温变化走势图 • 三个地区的平均温度以及平均温度的平均值 • 三个地区的温度与其平均值的偏差值 • 三个地区每天温度的变化大小diff

  22. 数据分析和统计 创建m文件 数据录入 把直接从数据库中得到的数据复制进m文件中(要用矩阵形式)。并保存为temps.m

  23. 数据分析和统计 在命令窗口中输入»temps调用数据 >> d=1:31; % number the days of month >> plot (d, temps), xlable('Day of Month'),ylabel('Celsius'),title('Daily High temperature in three cities')

  24. 数据分析和统计 >> avgtemp=mean(temps) avgtemp = 11.9677 8.2258 19.8710 >> avgavg=mean(avgtemp) avgavg =13.3548 得到三个地区的平均气温以及平均气温的平均值 >> for i=1:3 tdev(:,i)=temps(:,i)-avgtemp(i); end 运用循环语句得到一个平均气温的(3*31)Matrix进行运算

  25. 数据分析和统计 最后用我们学过的diff来求每日气温偏差 >> dailychange=diff(temps)

  26. 数据分析和统计 以上例子仅为matlab在统计计算的冰山一角,有关细节请参考专业书籍 谢谢观看

More Related