
Mastering 2D Plotting in MATLAB for Effective Data Visualization
Discover the power of 2D plotting in MATLAB for data representation and analysis. Learn how to create simple plots, add titles, axis labels, grid lines, and annotations. Enhance your understanding of plotting techniques to effectively visualize data relationships and patterns. Explore different styles, colors, and markers to customize your plots and make them more informative and visually appealing.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
AL-Mustaqbal University College COMPUTER APPLICATIONS: MATLAB Dr. Mayas Aljibawi 1
Lecture Number 2 2D plotting 2
What is Plotting A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variables. The plot can be drawn by hand or by a computer. ... Graphs of functions are used in mathematics, sciences, engineering, technology, finance, and other areas. MATLAB has an excellent set of graphic tools. Plotting a given data set or the results of computation is possible with very few commands. 3
Creating Simple 2D Plots The basic MATLAB graphing procedure for example, in 2D, is to take a vector of x-coordinates, x = (x1, .., xN), and a vector of y-coordinates, y = (y1, ..,yN), locate the points (xi, yi), where i = 1, 2, ..,N and then join them by straight lines. You need to prepare x and y in an identical array form; namely, x and y are both row arrays and column arrays of of the the same same length length. . The MATLAB command to plot a graph is plot(x Other Other plotting plotting commands commands: : plot(x , , y) y). . stem, Polar , compass, rose, loglog, semilogx, semiology, area stem, Polar , compass, rose, loglog, semilogx, semiology, area , fill, Pie, hist, stairs , fill, Pie, hist, stairs 4
Example >> n=5; >> x=0:1/n:3; >> y= sin(5*x); >> plot (x,y) >> n=25; >> x= 0:1/n:3; >> y= sin(5*x); >> plot (x,y) 5
Adding Titles, Axis Labels, Grid , Line Style and Annotations MATLAB enables you to add axis labels, grid and titles. x = 0:pi/100:2*pi; y = sin(x); plot(x,y), xlabel ('x = 0:2\pi') ylabel ('Sine of x') title ('Plot of the Sine function') grid % Remove grid by calling grid off 6
Cont.. The color of a single curve is, by default, blue. However, other colors are possible. The line styles, colors, and markers (e.g., circles, plus signs,. ) can be specified using the plot command: >> plot (x,y, style_color_marker ) Another colors and line styles can be used , see Table below: 7
Example Write a program to plot cos(2x) where the range of x from 1 to 10 in step of 0.1 with dotted line style and circle mark. x=1:0.1:10; y= cos(2*x); plot(x,y, : o ) xlabel('x ) ylabel('cos(2x) ) title('cos function ) 8
Example Write a program to plot 2*sin and 2*cos of x, where the range of x from 1 to 10 in step of 0.1 with dotted line style and circle mark. x=1:0.1:10; y= cos(2*x); plot(x,y,': o') hold y=sin(2*x); plot(x,y) xlabel('x') ylabel('cos(2x) and sin(2*x)') title( cos and sin function') legend({'COS(2X)',' SIN(2X)'},'FontSize',14) 9
End 10