Introduction To MATLAB: Ashraf Al-Rimawi Matlab 12-12-2008
Introduction To MATLAB: Ashraf Al-Rimawi Matlab 12-12-2008
22 100
100 55 44
11 22 33 44
aa==
11 22
33 44
>>cat_a
>> cat_a==[a[a 2*a;
2*a;3*a
3*a 4*a;
4*a;5*a
5*a 6*a]
6*a]
cat_a==
cat_a
11 22 22 44
33 44 66 88
33 66 44 88
99 12
12 12 12 1616 4*a
55 10
10 66 12 12
15 20
15 20 18 18 2424
>>AA==[1
>> [1559;4
9;4332.5;
2.5;0.1
0.110
103i+1]
3i+1]
AA==
1.0000
1.0000 5.0000
5.0000 9.0000
9.0000
4.0000
4.0000 3.0000
3.0000 2.5000
2.5000
0.1000
0.1000 10.0000
10.0000 1.0000++3.0000i
1.0000 3.0000i
>>A(:,2)=[]
>> A(:,2)=[]
Deleting Col. 2
A
A= =
1.0000
1.0000 9.0000
9.0000
4.0000
4.0000 2.5000
2.5000
0.1000
0.1000 1.0000++3.0000i
1.0000 3.0000i
>>A(2,2)=[]
>> A(2,2)=[]
??? Indexed
??? Indexedempty
emptymatrix
matrixassignment
assignmentisisnot
notallowed.
allowed.
Operator Function
Operator Function
++ Addition
Addition
** or
or .*.* Multiplication
Multiplication
// or
or ././ Division
Division
^^ or
or .^.^ Power (x^2
Power (x^2 == x*x)
x*x)
‘‘ Transpose
Transpose
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y) 1
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
Now label the axes, add a title and show the grid
>>xlabel('x = 0:2\pi')
Plot of the Sine Function
>>ylabel('Sine of x') 1
>>grid
0.6
0.4
0.2
Sine of x
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
x = 0:2
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
0.8
•• Example
Example 0.6
>>x1
>> x1==0:pi/100:2*pi;
0:pi/100:2*pi; 0.4
0.2
>>x2
>> x2==0:pi/10:2*pi;
0:pi/10:2*pi; 0
>>plot(x1,sin(x1),'r:',x2,sin(x2),'r+');
plot(x1,sin(x1),'r:',x2,sin(x2),'r+');
-0.2
>> -0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
0.8
0.4
0.2
-0.4
-0.8
the period -1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
>>x1
>> x1==0:pi/100:2*pi;
0:pi/100:2*pi; 0.8
>>x2
>> x2==0:pi/10:2*pi;
0:pi/10:2*pi; 0.6
>>plot(x1,sin(x1),'r:',x2,sin(x2),'bd')
>> plot(x1,sin(x1),'r:',x2,sin(x2),'bd') 0.4
>>grid
>> grid 0.2
>>x3
>> x3==0:pi/100:2*pi;
0:pi/100:2*pi; 0
-0.2
>>x4
>> x4==0:pi/10:2*pi;
0:pi/10:2*pi;
-0.4
>>hold
>> hold%%current
currentplot
plotheld
held
-0.6
>>plot(x1,cos(x1),'r:',x2,cos(x2),'bd')
>> plot(x1,cos(x1),'r:',x2,cos(x2),'bd') -0.8
>>hold
>> holdoff
off -1
0 1 2 3 4 5 6 7
Holds
Release
thethe
current
plot plot
Ashraf AL-Rimawi MATLAB 12-12-2008
Multiple Plots in One Figure
•• Example
Example
>>subplot(2,2,1);plot(x1,cos(x1),'r:',x2,cos(x2),'bd')
>> subplot(2,2,1);plot(x1,cos(x1),'r:',x2,cos(x2),'bd')
>>subplot(2,2,2);plot(x1,sin(x1),'r:',x2,sin(x2),'bd')
>> subplot(2,2,2);plot(x1,sin(x1),'r:',x2,sin(x2),'bd')
>>subplot(2,2,3);plot(x1,cosh(x1),'r:',x2,cosh(x2),'bd')
>> subplot(2,2,3);plot(x1,cosh(x1),'r:',x2,cosh(x2),'bd')
>>subplot(2,2,4);plot(x1,sinh(x1),'r:',x2,sinh(x2),'bd')
>> subplot(2,2,4);plot(x1,sinh(x1),'r:',x2,sinh(x2),'bd')
Try This !!
subplot(2,2,2);plot
subplot(2,2,2); plot......
subplot(2,2,3);plot
subplot(2,2,3); plot......
subplot(2,2,4);plot
subplot(2,2,4); plot......
File > export > choose the suitable format JPEG, TIFF, bmp ...
Encapsulatedcolor
Encapsulated color
•• Examples
Examples Postscriptstiff
Postscripts tiff
print-depsc
print -depsc-tiff
-tifffig.eps
fig.eps imagein
image infig.eps
fig.eps
print-dtiff
print -dtiff-r200
-r200fig.tiff
fig.tiff
Savethe
Save thefigure
figureasas
Tiffwith
Tiff withresolution
resolution
200dpi
200 dpiin
infig.tiff
fig.tiff
Use help to see other types, Try One !!
Ashraf AL-Rimawi MATLAB 12-12-2008