Download presentation
Presentation is loading. Please wait.
Published byAnnabelle Garrison Modified over 9 years ago
1
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept. http://www.bmabdelaty.faculty.zu.edu.eg/Default.aspx
2
Assignment Write a function called int_col that has one input argument, a positive integer n that is greater than 1, and one output argument v that is a column vector of length n containing all the positive integers smaller than or equal to n, arranged in such a way that no element of the vector equals its own index. In other words, v(k) is not equal to k for any valid index k. 2
3
In the previous lectures 3 Matlab Windows (workspace, m-file,…) Working with Arrays Mathematical Operations with Arrays Generating Random numbers Using Script Files and Managing Data
4
Agenda 4 Plotting given data and functions. Plotting multiple graphs in the same plot. Formatting a plot. Special plots: error bars, pie, histogram. Plotting multiple plots in the same page.
5
Powerful Tool 5 Standard plots with linear axis. Plots with logarithmic, semi-logarithmic axis, bar, stairs plots, three-dimensional contour surface and others. You can control the line type (solid, dash,…), color, thickness, grid lines and text comments. Several plots can be placed in the same page. A legend can be added…
6
6 Terminology
7
7 The two vectors have the same number of elements. The plot Command
8
8 Continuous line
9
9 The plot Command optional arguments
10
10 The plot Command optional arguments
11
11 The plot Command optional arguments
12
12 You can also control: The plot Command optional arguments
13
13 Example: Plotting given data
14
14 Example: Plotting given data
15
15 To plot a function y=f(x), you have first to create a vector of values for x, then the vector of y is calculated element by element. Plotting a function
16
16 Plotting a function Notice the small spacing between x values: 0.01.
17
17 The fplot command
18
18 Using Plot : Example: Plotting multiple graphs in the same Plot
19
19 Using Plot : Example: Plotting multiple graphs in the same Plot
20
20 Using hold on / hold off commands: Example: Plotting multiple graphs in the same Plot
21
21 Using hold on / hold off commands: Example: Plotting multiple graphs in the same Plot
22
22 Using hold on / hold off commands: Example modification Plotting multiple graphs in the same Plot New figure Without figure, hold off will erase the previous plots and keep only next plot.
23
23 Using hold on / hold off commands: Example modification Plotting multiple graphs in the same Plot
24
24 Formatting a plot
25
25 Formatting a plot
26
26 Formatting a plot
27
27 Example: Formatting a plot
28
28 Example: Formatting a plot
29
29 Plots with error bars
30
30 Plots with special graphs
31
31 Plots with special graphs
32
32 Histograms are plots that show the distribution of data. The overall range of a given set of data points is divided into subranges (bins). The histogram shows how many data points are in each bin. The histogram is a vertical bar plot in which the width of each bar is equal to the range of the corresponding bin and the height Histogram
33
33 Histogram
34
34 You can change the number of bins: Histogram
35
35 You can change the number of bins: Example: Histogram
36
36 subplot command: The command divides the Figure Window (and the page when printed) into mxn rectangular subplots. The subplots are numbered from 1 to ( mxn ), the current plot is p. Putting multiple plots in the same page
37
37 subplot command: Example: Putting multiple plots in the same page
38
Material & problems 38 We have covered Chapter 5 from Gilat. Problems you can try: Sample Problem 5-2 1—5, 11, 18, 19, 31
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.