Matlab操作技巧(不断更新)

1    转置

    Matlab中转置分为为两种,共轭转置和非共轭转置;

    共轭转置 ;

    非共轭转置 ;

    注意:非共轭转置下面有一个.;

    例子:

close all;clc;clear all;
%%  转置
 a = [1 2 3 4 5 6];
 b = [1 2 3 4 5 6];
 c = a + 1j*b;
 % 复数
 c1 = c'; % 共轭转置
 c2 = c.'; % 非共轭转置
 % 实数
 a1 = a';% 共轭转置
 a2 = a.'; % 非共轭转置

    结果展示:

    1.1 复数C

    

    1.2 实数a

    

2      读取文件信息函数


  函数dir,help得到的结果:


可以看到,这个函数的输出包括:

1.        文件名;

2.        文件的时间(这边我做了实验应该最近的修改时间);

3.        文件大小(Bytes);

4.        Isdir:返回1,代表是文件夹;返回0,代表不是;

5.        datenum:日期字符串转换为日期数字。

下面来一个例子:

%%  读取txt文件信息
RawDataPath1 = 'dir';  % 文件路径
RawDataPath2 = 'dir/dir_TXT.txt';  % txt路径
listing1 = dir(RawDataPath1); %文件
listing2 = dir(RawDataPath2); %txt

结果展示:

    

3      读取文件函数、大小、路径



4      取整

Matlab取整函数有: fix, floor,ceil, round。

1)        fix :朝零方向取整,如fix(-1.3)=-1;fix(1.3)=1;

    >> fix(-1.3)

    ans =

    -1

    >> fix(1.3)

    ans =

    1

2)        floor:朝负无穷方向取整,如floor(-1.3)=-2;floor(1.3)=1;

    >> floor(-1.3)

    ans =

    -2

    >> floor(1.3)

    ans =

    1

3)        ceil:朝正无穷方向取整,如ceil(-1.3)=-1;ceil(1.3)=2;

    >> ceil(-1.3)

    ans =

    -1

    >> ceil(1.3)

    ans =

    2

4)        round:四舍五入到最近的整数,如round(-1.3)=-1;round(-1.52)=-2;round(1.3)=1;round(1.52)=2。

    >>round(-1.3)

    ans =

    -1

    >> round(-1.52)

    ans =

    -2

    >> round(1.3)

    ans =

    1

    >> round(1.52)

    ans =

    2











猜你喜欢

转载自blog.csdn.net/yanchuan23/article/details/80568216