• matlab-变量类型-数组-矩阵


    1 变量类型

    1.1基本

     1.2 特殊变量

    1. ans
    2. •i,j: complex number
    3. •Inf: 无穷大
    4. •eps: 2.2204e-016
    5. •NaN: not a number
    6. •pi:pai

     

    注意:关键字是可以做变量的

    1.3 numeric display format

    1.4 some useful functions

    1. •clc: clear command windowdisplay
    2. •clear: remove all variables in the workspace
    3. •who: variables in the workspace
    4. •whos: variable information of the workspace

    2 数组

    1.1 定义

    row vector:
    >> a = [1 2 3 4]
    column vector:
    >> b= [1; 2; 3; 4]

    1.2 数组下标 

    Select a certain subset of elements inside a matrix


    •What’s the answer from MATLAB after typing?
    >> A(8)

      9
    >> A([1 3 5])

      1  31  17 
    >> A([1 3; 1 3])

     

     
    >> A(3,2)

      2
    >> A([1 3], [1 3])

    1.3 Colon Operator

    •Want to create a long array:A= [12 3 … 100]
    •Creates vectors or arrays, and specify for iterations
    •Syntax:


    •What’s the answer from MATLAB after typing?
    >> B = 1:5

    1 2 3 4 5 
    >> B = 1:2:5

    1 3 5
    >> B = [1:5; 2:3:15; -2:0.5:0]

    1        2     3      4       5

    2        5     8     11     13

    -2    -1.5   -1    -0.5    0  

    >>str= 'a':2:'z'

    a b c ... z

     

    1.4 Array Concatenation

    1.5 Array Manipulation

    数组运算

    >> x1=A+a

    每个都加2

    >> y1=A+B

    对应位想加


    >> x2=A/a

    每位都除以a

    >> y2=A*B


    >> x3=A./a

    对应位相乘a

    >> y3=A.*B

    对应位相乘


    >> x4=A^a

    a个A相乘

    >> y5=A./B

    对应位想除

    >>C=A'

    转置矩阵

     

     Some Special Matrix

    一些特殊的矩阵

    Matrix Related Functions

     一些矩阵函数

    >>max(A)

    >>max(max((A))

    结果是   9

    也就是对上面的[9 8 7 ] 中取最大的

    >>sort(A)

    从小到大  按照列排序

    >>sortrows(A)

    从小到大  按照行排序
    >> min(A)

    参照最大

    >> size(A)

    结果是  3 3  表示有3行3列
    >> sum(A)

    对每列求和

  • 相关阅读:
    MVC4中EasyUI Tree异步加载JSON数据生成树
    Linq语法
    委托的多种写法
    centos7安装Hive2.3.0
    ApacheKylin笔记
    把普通的JavaProject变成MavenProject
    eclipse 手动/自动安装插件
    我的JdbcUtils类
    Druid 连接池 JDBCUtils 工具类的使用
    Maven下载cxf所需要的jar包
  • 原文地址:https://www.cnblogs.com/liu-wang/p/9027016.html
Copyright © 2020-2023  润新知