Script writing
Matlab Script
A file containing a series of MATLAB commands
Pretty much like a C/C++ program
Scripts need to be saved to a <file>.m file before they can be run
Start A Script (m) File
......
Script Editor
文件名 不可以数字开头 大小写区分
%% section
% 注释
breakpoint 断点
smart indent 智能缩排
Script Flow
Typically scripts run from the first line to the last
Structured programming techniques (subroutine, loop, condition, etc) are applied to make the
program looks neat
Flow Control
if elseif else
for
switch case
while
break
continue
end
Relation(Logical) Operators
< <=
> >=
== ~=
&& ||
Structured programming
if elseif else
if condition1
statement1
elseif condition2
statement2
else
statement3
end
"elseif" and 'else" are optional
switch
switch expression
case value1
statement1
case value2
statement2
otherwise
statement
end
while
while expression
statement
end
for
for variable=start: increment: end
commands
end
Pre-allocating Space to Variables
break
Tips for Script Writing
User-defined function
注意点乘