1、循環
for i=n:-1:1
n是i的初始值,-1是步長,1是終止值。
2、輸入數字
?x=input('please input a number:')
please input a number:22
x = 22
輸入字符串
?x=input('please input a string:','s')
please input a string:this is a string
x = this is a string
3、輸出語句
輸出顯示命令
自由格式 (disp)
?disp(23+454-29*4)
361
?disp([11 22 33; 44 55 66; 77 88 99])
11 22 33
44 55 66
77 88 99
?disp('this is a string')
this is a string
格式化輸出 (fprintf)。
fprintf('The area is %8.5f\n', area) % 注意輸出格式前須有%符號,
%跳行符號須有\符號
The area is 12.56637 % 輸出值爲8位數含5位小數
在這裏你如果學過c語言就能很好的理解了。
4、錯誤消息顯示命令
?error('this is an error')
??? this is an error
5、;用不用的區別
>> i=3;
>> i=3
i =3
6、clc 清除命令
7、 A(:,1:2:3)
A的第1、3列