Академический Документы
Профессиональный Документы
Культура Документы
Note: To change current interface into this typical interface Click Layout Select Layout
Click on Default Then click Layout again Click on command history Choose Docked
a) Command Window To type commands and usually answers (or error messages) will be
appear at this area. >> means Matlab waiting for further instruction.
b) Workspace window Variables that has been define in command window (as well in mfiles) should be listed here.
c) Command history window The past commands are remembered here. We can re-run the
previous command or to edit the command by drag it to command window.
Example: pi
>> format long
>> pi
ans =
3.141592653589793
>> format short
>> pi
ans =
3.1416
>> format short e
>> pi
ans =
3.1416e+00
Part 2: Simple arithmetic operator
a)
b)
c)
d)
e)
Additional: +
Subtraction: - ,
Multiplication: *
Division: /
Power: ^
Example:
>>3+5-7
ans=
1
Or
>>t=3+5-7
t=
1
>>T=2*t+2
T=
4
Note: Variable names Capital letter (A) and small letter (a) will brings difference variable
value.
Part 4: Trigonometric
(a) Tangent, sine & cosine of argument
Example: cos (15) in radian
>> cos(15)
% without d : radians
ans =
-0.7597
% with d: degree
ans =
0.9659
% without d : radians
ans =
1.0472
% with d: degree
ans =
60.0000
>> B = [1;2;3;4;5]
B=
1
2
3
4
5
>> C = [1 2; 3 4; 5 6]
C=
1 2
3 4
5 6
>> C(2,:)
ans =
3
Part 7: Logical
In Matlab the integer 1 represents true and 0 represent false.
Example:
>>X = 14
>>X > 10
ans =
1
Example:
>>Y=[0 -1 2 4]
>>Y>2
ans =
0001
Command
Result
Description
Y==2
[0 0 1 0]
Entries equal to 2
Y>2
[0 0 0 1]
greater than 2
Y>=2
[0 0 1 1]
Y<2
[1 1 0 0]
less than
Y<=2
[1 1 1 0]
Y~=2
[1 1 0 1]
not equal to
>>Y<0|Y>1
ans =
0111