Professional Documents
Culture Documents
Matlab
Matlab
Matrix Laboratory
Matlab
(>>) M-files Simulink
Matlab
Matlab Workspace Variables/Current Directory
( Matlab )
Command History
( Matlab )
Command Window
(all Matlab versions)
Matlab
Operators Matrices Plotting M-files Flow control Simulink Misc commands Simulink
Operators
+ * / \ ^
( (
) )
L R L R L R
Operators
() ^ */ +-
/ /
>> 6*5 ans = 30 >> 17/5 ans = 3.4000 >> ans ans = 3.4000
Operators
>> x=6*5 x= 30 >> y=17/5; >> y y= 3.4000 >> z=x+y z= 33.4000 >> who Your variables are: x y z
(;)
Operators
:
>>case_34=6.45; >>case34=6.45;
Operators
:
34case, ge204!, Name Here case34, ge204, Name_Here
Matlab
8 :
>> p = 3; >> p = 3.0;
: :
Operators
:
>> a = 4; >> A = 10; 10; >> clear a
A{ a
Matlab
exp(x) sin(x) asin(x) log(x) log10(x) sqrt(x) abs(x) sum(x) ex sin x sin-1x ln x log x pi i,j NaN Inf T imaginary unit Not-a-Number g
Operators
x
|x|
Matlab
: :
>>y=x^0.5; >>y=x^(1/2); >>y=sqrt(x);
Operators
y! x
Matlab Help
>>help
Operators
Matlab
Matlab Help
>> help sqrt
Operators
Matlab Help
help
Operators
Matlab
[]
Arrays
(
>> A=[6 5; 3 4] A= 6 5 3 4 >> A(1,1)=10 A= 10 5 3 4 >> 1:2:7 ans= 1 3 5 7 >> 1:4 ans= 1 2 3 4
)
: ( initial:step:final initial:step: : : (1 )
Arrays
Arrays
Arrays
)
Matlab
C!A B
1
C ! BA
1
Matlab >>C=A;
1 2 3 A! 4 5 6
Arrays
C=AT
>>B=A; 1 4 B ! 2 5 3 6
1 2 3 A! 4 5 6
2 3 4 B! 5 6 7
1 2 3 2 3 4 D! 4 5 6 5 6 7
Matlab
>> >> >> >> >> >> x=0:.1:20; y=exp(0.1*x).*sin(x); plot(x,y) xlabel('Time (t) in Seconds') ylabel('Response in mm') title('A Simple 2-D Plot')
Matlab
Plotting
plot
>> n=0:11; >> y=sin((pi/6)*n);
! , y1, x1
>> plot(n,y)
Plotting
>> plot(n,y,'--')
subplot
subplot(m subplot(m,n,p)
Plotting
Plotting
Matlab
Matlab Matlab :
Script files ( Function files (
M-Files
) )
.m
(M-files) M
:M-file
>>edit filename New > M-file
M-Files
Script Files
:script
) (test
M-Files
script
function [list of outputs] = aaa(list of inputs) % function help . . . program . . . return ) Matlab !(
M-Files
cmb function [x,y]=cmb(a,b) %Test function Command x=a+b; Window y=a/b; return >> [j,k]=cmb(5,2) j=7 k=2.5 >>help cmb Test function
M-Files
Flow control
: ( )
if if-else while for ...
while
while expression statements end
if
if expression statements1 else statements2 end
Flow control
(statements)
(while)
>> a=1; >> while a<5 a=a+1 end a = 2 a = 3 a = 4 a = 5 >> a=10; >> while a<5 a=a+1 end >> a a = 10 >> a=1; >> while a<5 b=a+1 end b = 2 b = 3 b = 4 b = 5 b = 6 b = 7 . . . g loop! .
Flow control
for
!
for index = start : [increment :] end statements end
1
Flow control
(increment)
>
<
Flow control
>> for a=1:5 a end a = 1 a = 2 a = 3 a = 4 a = 5 >> for a=1:5 f(a)=a; end >> f 1 2 3 4 5 >>size(f) ans = 1 5
sym) (
Misc. commands
Misc. commands