第三讲 MATLAB程序设计课件.pptVIP

  • 0
  • 0
  • 约3.5千字
  • 约 85页
  • 2017-08-19 发布于河南
  • 举报
第三讲 MATLAB程序设计课件

第三讲 MATLAB程序设计;3.1 M文件; ; ; ;function r = rank(A,tol) %RANK Matrix rank. % RANK(A) provides an estimate of the number of linearly % independent rows or columns of a matrix A. % RANK(A,tol) is the number of singular values of A % that are larger than tol. % RANK(A) uses the default tol = max(size(A)) * eps(norm(A)). % % Class support for input A: % float: double, single % Copyright 1984-2004 The MathWorks, Inc. % $Revision: 5.11.4.3 $ $Date: 2004/08/20 19:50:33 $ s = svd(A); if nargin==1 tol = max(size(A)) * eps(max(s)); end r = sum(s tol);;3.2 数据的输入输出; ;b = 2 3 4 5 6 7 8 9 0 disp (b) 2 3 4 5 6 7 8 9 0; ; ; 3.3 选择结构; ;例3.4计算分段函数值。;例3.5 输入数n,判断其奇偶性; ; ;; ; ; ; ; ; 3.4 循环结构; ; ; ; ; ; ;与循环结构相关的还有一个break语句,当在循环体内执行到语句时,程序将跳出循环。语句一般与if语句配合使用。 在多重循环中,break只能使程序跳出包含它的最内层的那个循环; ; ; ; 3.5 函数文件; ; ; ; ; ; ; 3.6 全局变量和局部变量;数值数据(Numeric):双精度型(double)、单精度数、带符号整数(int8)和无符号整数(uint8)。 字符数据(char) 。 结构型(structure)和细胞型(cell)。 稀疏型(sparse)。 ;结构和单元;1. 结构矩阵的建立与引用; student(2).name = David; student(2).num = 123532; student(2).test=[68 70 68;118 118 119;172 170 169; 23 543 433]; student student = 1x2 struct array with fields: name num test fieldnames(student) ans = name num test;(2) 用函数struct定义,调用格式: 结构数组名 = struct (‘属性1’,‘属性值1’,‘属性2’,‘属性值2’,… ) s = … struct(type,{big,little},color,red,x,{3 4}) ;2. 结构成员的修改; ; ;1. 细胞矩阵的生成和引用;C={[1 2],[3 4];[5 6],[7 8]} 生成一个2X2的细胞数组,数组每个元素都为1X2的数值矩阵。;综合使用大括号和小括号可以取出细胞数组的某个元素或某些元素的值,也可取出某个元素值的一部分。 c=A{1,2} d=A{1,1}(2,2) c=A(2:2,1:2); ;3.9 文件操作 (Low-Level File I/O Functions);filename = input(‘Open file:’,’s’); [fid,message] = fopen (filename,’r’); if fid==-1 disp ( message); end; ; ; ; ;?;Importing and Exporting Data;Importing Text Data;Using the Import Wizard with Text Data;Data Format Sample;Function ;Function ;1. Importing Numeric Text Data; load my_data.txt whos Name Size

文档评论(0)

1亿VIP精品文档

相关文档