matlab2

228 阅读1分钟

%的用法

一个%表示注释

两个%%可以把程序分区块

条件语句

不等于:~=

if conditon1
 statement1
elseif condition2
 statement2
else
 statmment3
end
switch expression
case value1
 statement1
case value2
 statement2
.
.
otherwise
 statement
end

循环语句

while expression
 statement
end
for variable = start : increment : end
 commands
end

小技巧

用三个点来换行

A = [1 2 3 4 5 6; ...
6 5 4 3 2 1];

Function

function y = mean(x)
...

function [a F] = acc(v2, v1, t2, t1, m)
...

Function handle

f = @(x)exp(-2*x)
x = 0:0.1:2
plot(x, f(x))