lecture (4)
DESCRIPTION
Lecture (4). Plotting & Programming (1) Eng. Osama Talaat. Plotting. 0. t. 1. 2. 3. 4. 5. 5.18. s. -. 6.08. 24.97. 36. 54.98. 66.07. Plotting. 0. t. 1. 2. 3. 4. 5. 5.18. s. -. 6.08. 24.97. 36. 54.98. 66.07. Plotting : Line Colors. >> plot( t,s,'r ') Colors: - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/1.jpg)
1Lecture (4)
Plotting & Programming (1)Eng. Osama Talaat
![Page 2: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/2.jpg)
2 Plotting
t 0 1 2 3 4 5s -5.18 6.08 24.97 36 54.98 66.07
![Page 3: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/3.jpg)
3 Plotting
t 0 1 2 3 4 5s -5.18 6.08 24.97 36 54.98 66.07
![Page 4: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/4.jpg)
4 Plotting: Line Colors>> plot(t,s,'r')Colors: 'r': red 'g': green 'y': yellow 'b': blue 'w': white 'k': black
![Page 5: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/5.jpg)
5 Plotting: Line Style>> plot(t,s,'--') '-': Solid '--': Dashed ':': Dotted '-.': Dash-Dot '+': Plus signs '*': Asterisks 'x': Crosses 's': Squares 'd': Diamonds
![Page 6: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/6.jpg)
6 Plotting: Line Style & Color Red Dashed line:
>> plot(t,s,'r--') >> plot(t,s,'--r')
![Page 7: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/7.jpg)
7 Plotting Titles X-Axis Title:
>> xlabel('time')
![Page 8: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/8.jpg)
8 Plotting Titles Y-Axis Title:
>> ylabel('Speed')
![Page 9: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/9.jpg)
9 Plotting Titles Graph Title:
>> title('Speed Curve')
![Page 10: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/10.jpg)
10 Plotting Grid>> grid
![Page 11: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/11.jpg)
11 Plotting: Texts Using Coordinates:
>> text(0.6,-2,'Point(0.5,0)')
![Page 12: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/12.jpg)
12 Plotting: Texts Using Mouse:
>> gtext('Point(0.5,0)')
![Page 13: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/13.jpg)
13 Plotting: Axis Limits X-Axis Limits:
>> xlim([0.5 4])
![Page 14: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/14.jpg)
14 Plotting: Axis Limits Y-Axis Limits:
>> ylim([-20 50])
![Page 15: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/15.jpg)
15 Plotting: Figure window
ClickHere
![Page 16: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/16.jpg)
16 Plotting in the same figure Close all windows. Plot sin(x)
>> x=0:0.1:4*pi;
>> plot(x,sin(x))
Plot 2cos(x)>> plot(x,2*cos(x))
???
![Page 17: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/17.jpg)
17 Plotting in the same figure>> x=0:0.1:4*pi;>> y1=sin(x);>> y2=2*cos(x);>> plot(x,y1,x,y2)>> plot(x,y1,'r',x,y2,'--b')
![Page 18: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/18.jpg)
18 Plotting in the same figure>> plot(x,y1,'r')>> hold on>> plot(x,y2,'--b')>> hold off
![Page 19: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/19.jpg)
19 Plotting in the same figure: Legend>> legend('sin(x)','2cos(x)')
![Page 20: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/20.jpg)
20 Plotting in separate figures>> plot(x,y1,'r')>> figure>> plot(x,y2,'--b')
![Page 21: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/21.jpg)
21 Test yourself !!>> close all Insert each graph titles and grid ??>> plot(x,y1,'r')>> xlabel('x')>> ylabel('y1')>> title('sin(x)')>> grid>> figure>> plot(x,y2,'--b')>> xlabel('x')>> ylabel('y2')>> title('2cos(x)')>> grid
![Page 22: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/22.jpg)
22 Subplotting
![Page 23: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/23.jpg)
23 Subplotting>> subplot(2,2,1)
![Page 24: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/24.jpg)
24 Subplotting>> plot(x,sin(x))
![Page 25: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/25.jpg)
25 Subplotting>> title('sin(x)'); grid
![Page 26: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/26.jpg)
26 Subplotting>> subplot(2,2,2)
![Page 27: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/27.jpg)
27 Subplotting>> plot(x,cos(x)); title('cos(x)'); grid
![Page 28: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/28.jpg)
28 Subplotting>> subplot(2,2,3)
>> plot(x,sin(2*x))
>> title('sin(2x)')
>> grid
>> subplot(2,2,4)
>> plot(x,cos(2*x))
>> title('cos(2x)')
>> grid
![Page 29: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/29.jpg)
29 NB: Variable Plottingx = [2 3 4 12 15 14]
>> x = [2 3 4 12 15 14];>> plot(x)
1 2 3 4 5 6
![Page 30: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/30.jpg)
30 Other Plotting Functions>> area(x,sin(x))
![Page 31: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/31.jpg)
31 Other Plotting Functions>> stairs(x,sin(x))
![Page 32: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/32.jpg)
32 Other Plotting Functions>> bar([2001:2006],[13 15 17 20 6 12])
![Page 33: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/33.jpg)
33 Other Plotting Functions>> pie([15 23 57 5])
![Page 34: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/34.jpg)
34 Other Plotting Functions>> pie3([15 23 57 5])
![Page 35: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/35.jpg)
35 Other Plotting Functions Plotting an equation
>> ezplot('(x^2+y^2-1)^3-x^2*y^3=0')
>> xlim([-1.5 1.5])
>> ylim([-1.5 1.5])
![Page 36: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/36.jpg)
36 Polar Coordinates>> th=0:0.01:2*pi;>> r=sin(4*th);>> polar(th,r)
![Page 37: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/37.jpg)
37 3D Plotting: Curve>> t=0:0.1:10*pi; plot3(sin(t),cos(t),t); grid
![Page 38: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/38.jpg)
38 Test Yourself !! Insert Z-Axis Label:>> zlabel('height')
![Page 39: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/39.jpg)
39 3D Plotting: Surface
![Page 40: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/40.jpg)
40 3D Plotting: Surface
>> [x,y]=meshgrid(-2:0.1:2,-2:0.1:2);>> z=x.*exp(-x.^2-y.^2);>> surf(x,y,z)
![Page 41: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/41.jpg)
41 3D Plotting: Surface>> mesh(x,y,z)
![Page 42: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/42.jpg)
42 Special Surfaces Sphere
>> sphere
![Page 43: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/43.jpg)
43 Special Surfaces Cylinder
>> cylinder
![Page 44: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/44.jpg)
44 Special Surfaces MATLAB Logo
>> logo
![Page 45: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/45.jpg)
45Introduction to Programming
Create New Program: Ctrl + N New button File menu >> New >> script
![Page 46: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/46.jpg)
46
x=[0:0.1:2*pi];y=sin(x);plot(x,y)xlabel('x')ylabel('sin(x)')title('Sine Curve')grid!!')
![Page 47: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/47.jpg)
47
clear all;close all;clc;
x=[0:0.1:2*pi];y=sin(x);plot(x,y)xlabel('x')ylabel('sin(x)')title('Sine Curve')grid
Clean
Start
![Page 48: Lecture (4)](https://reader036.vdocuments.us/reader036/viewer/2022062501/568163ae550346895dd4c311/html5/thumbnails/48.jpg)
48 GOOD LUCKTo be continued in the next lecture …