matlab简介 基本操作

1、快捷键:

  • Tab、Ctrl+] :增加缩进
  • Ctrl+[ :减少缩进
  • Ctrl+I:自动缩进
  • Ctrl+R:增加注释
  • Ctrl+T:去掉注释
  • F12:设置或清除断点
  • F5:运行

2、特殊变量:

  • i、j:虚数单位
  • inf、Inf:无穷大∞
  • eps:浮点运算的相对精度
  • realmax:最大正浮点数
  • nan:不定量
  • nargin:函数输入参数个数
  • lasterr:返回最新错误信息
  • lastwarn:返回最新警告信息

3、

  •  abs:绝对值  /  模
  • round:四舍五入到最接近的整数
  • floor:向负无穷方向取整
  • ceil:向正无穷方向取整
  • fix:向0方向取整
  • rem:求余
  • asin:反正弦
  • atan:反正切
  • angle:相位角
  • mean:均值
  • var:方差
  • corrcoef:相关系数
  • sign:符号函数
  • mod:取模
  • conj:共轭复数
  • std:标准差
  • cov:协方差
  • range:极差
  • plot:画线图

4、高维数组:

>> %2行,2列,2页
>> x(1:2,1:2,1)=[1 2;3 4];
>> x(1:2,1:2,2)=[5 6;7 8];
>> x

x(:,:,1) =

     1     2
     3     4

x(:,:,2) =

     5     6
     7     8

5、定义结构体数组:

>> %直接赋值
>> struct1(1).name='xiezhh';
>> struct1(2).name='heping';
>> struct1(1).age=31;
>> struct1(2).age=32;
>> struct1

struct1 = 

1x2 struct array with fields:

    name
    age
>> struct2=struct('name',{'xiezhh','helping'},'age',{31,32})

struct2 = 

1x2 struct array with fields:

    name
    age

>> struct2(1).name

ans =

xiezhh

6、定义元胞数组

不同类型,不同大小放一个数组里

>> c1={[1 2;3 4],'xiezhh',[5 6 7],'emmm'}

c1 = 

    [2x2 double]    'xiezhh'    [1x3 double]    'emmm'
>> c2=cell(2,4)

c2 = 

    []    []    []    []
    []    []    []    []

>> c2{2,3}=[1 2 3]

c2 = 

    []    []              []    []
    []    []    [1x3 double]    []
>> c1={[1 2;3 4],'xiezhh';[5 6 7],'emmm'}

c1 = 

    [2x2 double]    'xiezhh'
    [1x3 double]    'emmm'  

>> c1(2,2)

ans = 

    'emmm'

>> c1{2,2}

ans =

emmm

7、数组转换

  • mat2cell:矩阵分块,转为元胞
  • cell2mat:元胞->矩阵
  • num2cell:数值->元胞
  • cell2struct:元胞->结构
  • struct2cell:结构->元胞
>> a=rand(60,50);
>> b=mat2cell(a,[10,20,30],[25,25])

b = 

    [10x25 double]    [10x25 double]
    [20x25 double]    [20x25 double]
    [30x25 double]    [30x25 double]

>> c=cell2mat(b);
>> isequal(a,c)

ans =

     1
>> c={'zxc','xian',31;'sdfbn','shengzhen',26}

c = 

    'zxc'      'xian'         [31]
    'sdfbn'    'shengzhen'    [26]

>> fields={'Name','Adress','Age'};
>> s=cell2struct(c,fields,2)

s = 

2x1 struct array with fields:

    Name
    Adress
    Age

>> cs=struct2cell(s)

cs = 

    'zxc'     'sdfbn'    
    'xian'    'shengzhen'
    [  31]    [       26]

>> isequal(c,cs')

ans =

     1

8、

猜你喜欢

转载自www.cnblogs.com/ileanj1998/p/9058515.html