Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.

Similar presentations


Presentation on theme: "Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1."— Presentation transcript:

1 Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1

2 Plotting 2 t 0 12345 s- 5.18 6.0824.973654.9866.07

3 Plotting 3 t 0 12345 s- 5.18 6.0824.973654.9866.07

4 Plotting: Line Colors >> plot(t,s,'r') Colors:  ' r ' : red  ' g ' : green  ' y ' : yellow  ' b ' : blue  ' w ' : white  ' k ' : black 4

5 Plotting: Line Style >> plot(t,s,'--')  '-': Solid  '--': Dashed  ':': Dotted  '-.': Dash-Dot  '+': Plus signs  '*': Asterisks  'x': Crosses  's': Squares  'd': Diamonds 5

6 Plotting: Line Style & Color 6  Red Dashed line: >> plot(t,s,'r--') >> plot(t,s,'--r')

7 Plotting Titles 7  X-Axis Title: >> xlabel('time')

8 Plotting Titles  Y-Axis Title: >> ylabel('Speed') 8

9 Plotting Titles 9  Graph Title: >> title('Speed Curve')

10 Plotting Grid 10 >> grid

11 Plotting: Texts 11  Using Coordinates: >> text(0.6,-2,'Point(0.5,0)')

12 Plotting: Texts 12  Using Mouse: >> gtext('Point(0.5,0)')

13 Plotting: Axis Limits 13  X-Axis Limits: >> xlim([0.5 4])

14 Plotting: Axis Limits 14  Y-Axis Limits: >> ylim([-20 50])

15 Plotting: Figure window 15 Click Here

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))  ??? 16

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') 17

18 Plotting in the same figure >> plot(x,y1,'r') >> hold on >> plot(x,y2,'--b') >> hold off 18

19 Plotting in the same figure: Legend >> legend('sin(x)','2cos(x)') 19

20 Plotting in separate figures >> plot(x,y1,'r') >> figure >> plot(x,y2,'--b') 20

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 21

22 Subplotting 22

23 Subplotting >> subplot(2,2,1) 23

24 Subplotting >> plot(x,sin(x)) 24

25 Subplotting >> title('sin(x)'); grid 25

26 Subplotting >> subplot(2,2,2) 26

27 Subplotting >> plot(x,cos(x)); title('cos(x)'); grid 27

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 28

29 NB: Variable Plotting x = [2 3 4 12 15 14] >> x = [2 3 4 12 15 14]; >> plot(x) 29 1 2 3 4 5 6

30 Other Plotting Functions >> area(x,sin(x)) 30

31 Other Plotting Functions >> stairs(x,sin(x)) 31

32 Other Plotting Functions >> bar([2001:2006],[13 15 17 20 6 12]) 32

33 Other Plotting Functions >> pie([15 23 57 5]) 33

34 Other Plotting Functions >> pie3([15 23 57 5]) 34

35 Other Plotting Functions 35

36 Polar Coordinates >> th=0:0.01:2*pi; >> r=sin(4*th); >> polar(th,r) 36

37 3D Plotting: Curve >> t=0:0.1:10*pi; plot3(sin(t),cos(t),t); grid 37

38 Test Yourself !!  Insert Z-Axis Label: >> zlabel('height') 38

39 3D Plotting: Surface 39

40 3D Plotting: Surface 40

41 3D Plotting: Surface >> mesh(x,y,z) 41

42 Special Surfaces  Sphere >> sphere 42

43 Special Surfaces  Cylinder >> cylinder 43

44 Special Surfaces  MATLAB Logo >> logo 44

45 Introduction to Programming  Create New Program:  Ctrl + N  New button  File menu >> New >> script 45

46 x=[0:0.1:2*pi]; y=sin(x); plot(x,y) xlabel('x') ylabel('sin(x)') title('Sine Curve') grid !!') 46

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 47 CleanStart

48 GOOD LUCK To be continued in the next lecture … 48


Download ppt "Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1."

Similar presentations


Ads by Google