matlab简介 基本操作

时间:2018-05-19 01:02:36   收藏:0   阅读:294

1、快捷键:

2、特殊变量:

3、

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、数组转换

>> 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、

原文:https://www.cnblogs.com/ileanj1998/p/9058515.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!