MATLAB_台大郭彦甫_02基本操作与矩阵输入

将MATLAB当做计算器使用

MATLAB Programming Modes

使用MATLAB的两种方式:

  1. Command line (in command window)
  2. Scripts (.m files)

MATLAB as A Calculator

operators: +      -      *      /      ^

优先级:()      >      ^      >      * /      >      + -

ln -> log        e -> exp(1)       

Elementry Math Function(基本数学函数)

......

Embedding Function(嵌套函数)

......

Variable(变数)

MATLAB中变数不需要宣告

变数 = 变数/常数

Numeric Variable (Data)Type

默认类型为double

Special Variable and Constants

>> iskeyword

ans        i j        inf        eps        NaN        pi  ......

Matlab Calling Priority

>> cos = 'This string.';

>> cos(8)

>> clear cos

Numeric Display "Format"

short

long

shortE

longE

rat

Command Line Terminal

>> b = 10;        % 分号表示不显示运算结果

PgUp  ->  display previous commands

Some Functions

clc        

clear

who

whos


矩阵操作

Array(Vector and Matrix)

>> a = [1 2 3 4]

>> b = [1;2;3;4]

Array Indexing

1.序号索引

>> A(8)

>> A([1 3 5])

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

2.行,列索引

>> A(3,2)

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

Replacing Entries

>> A(1,2) = 76;

Colon Operator

>> A = [1:100];

>> A = [1:2:99];        % 步长

>> A(3,:) = [ ];        %第三行置空

调用函数或对变量进行索引时,使用圆括号

Array Concatenation

>> A = [B C];

>> A = [B;C];

Array Manipulation(矩阵的运算)

>> A = [1 2 3;4 5 4;9 8 7];

>> B = [3 3 3;2 4 9;1 3 1];

>> y1 = A+B

>> y2 = A*B

>> y3 = A.*B

>> y4 = A/B

>> y5 = A./B

>> x1 = A+a

>> x2 = A/a

>> x3 = A./a

>> x4 = A^a

>> x5 = A.^a

>> C = A'

Some Special Matrix

eye(n)        zeros(n1,n2)        ones(n1,n2)        diag()  % diag([1 2 3])

Some Matrix Related Functions

>> A = [1 2 3;0 5 6; 7 0 9]

>> max(A)        % 7 5 9 按每一列做运算

>> max(max(A))        % 矩阵的最大值

>> min(A)

>> sum(A)

>> mean(A)

>> sort(A)

>> sortrows(A)

>> size(A)

>> length(A)

>> find(A)        % find(A == 5)

  • 22
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值