Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.

Slides:



Advertisements
Similar presentations
Zhongxing Telecom Pakistan (Pvt.) Ltd
Advertisements

Chapter 16 Graphical User Interfaces
BASIC SKILLS AND TOOLS USING ACCESS
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Chapter 1 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Tutorial 3 – Creating a Multiple-Page Report
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Introduction to Matlab
Points, Vectors, Lines, Spheres and Matrices
1 SESSION 5 Graphs for data analysis. 2 Objectives To be able to use STATA to produce exploratory and presentation graphs In particular Bar Charts Histograms.
Mike Scott University of Texas at Austin
Introduction to Matlab
Introduction to R Brody Sandel. Topics Approaching your analysis Basic structure of R Basic programming Plotting Spatial data.
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
Chapter 7: Arrays In this chapter, you will learn about
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
Parallel List Ranking Advanced Algorithms & Data Structures Lecture Theme 17 Prof. Dr. Th. Ottmann Summer Semester 2006.
ABC Technology Project
Vanderbilt Business Objects Users Group 1 Reporting Techniques & Formatting Beginning & Advanced.
Chapter 11: The X Window System Guide To UNIX Using Linux Third Edition.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
from bonfires to lasers
ELE 532 – Signals and Systems Fall 2007 MATLAB Tutorial
1 POWERPOINT May 2004 To move the text box - move the mouse over the border of the text box, and once the 4-way arrow appear – click and drag the box.
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Addition 1’s to 20.
CS 240 Computer Programming 1
25 seconds left…...
Week 1.
We will resume in: 25 Minutes.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
Lesson One: The Beginning
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
Chapter 8 Improving the User Interface
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
2D Plots 1 ENGR 1181 MATLAB 12.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Introduction to Matlab Jianguo Wang CSSCR September 2009.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Computer Application in Engineering Design
Lecture 25: Exploring data
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Presentation transcript:

Lab # 03- SS Basic Graphic Commands

Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters on the graph. To plot multiple graphs in a single graph window.

M-Files/ Script files: 3 So far, you’ve seen that MATLAB can accept and execute commands interactively through the command prompt … what happens if you’ve got A LOT of commands to execute? You can do this in Matlab. This kind of file is called a script file or M-file (M for MATLAB!) You place all commands you want to execute in a file with extension.m at the end, and you run the script file MATLAB will run all of these commands in sequence for you. MATLAB has a M-file editor that you can use where you can create your scripts.

M-File 4

Script Files 5 Once a script file has been created, type in the name of the file (without the.m) in the command prompt to execute the script When you execute a script file, all of the variables created in the script file get stored in the workspace for future use The great thing about script files is that commands can be re- executed without having to enter them all again! All you have to do is modify parts of the script file to give you the result you want Let’s do an example: Let’s make the factorial example into a script file

Example #1 6

7

Lab Task-01 The script file is now set to compute 4! What if I wanted to do 9!, or 12!, or 5! ? Hint-Just change the n parameter accordingly

9 Basic Graphics Commands MATLAB provides a variety of sophisticated techniques for presenting and visualizing data. Also, MATLAB makes it very easy to plot data!

10 2D plotting: If x and y are arrays of elements that are the same size, you can plot them using this data with the following command: plot(x, y); This will bring up a window plotting a graph of y vs. x

11 Example # 02 Here’s a basic example: Let’s say I wanted to plot the line y = x Here’s the syntax: This is what the graph looks like… To use the ‘plot’ function in Matlab, you should first make sure that the matrices/vectors you are trying to use are of equal dimensions.

Lab Task-02 Plot the following: A) y1=2x B) y2=x+3 C) y3=2x+2z

13 Multiple plots on a single Graph: If you want to plot multiple plots on a single graph, you do the following: plot(x1,y1,x2,y2,…,xN,yN); N is the number of plots you want to appear on the single graph.

14 Example # 03 Let’s do another example: Let’s plot the following 5 lines: y1 = 0.1x y2 = 0.5x y3 = 2x y4 = 5x y5 = 10x For now, let’s make them all go from 0 to 10 in step sizes of 0.1 These plots don’t all have to have the same step size!

15 Write this in the command prompt in MATLAB You can also make a script file too if you want!

16 MATLAB automatically color codes the different plots that are on the graph You can add a title, label the axes, put a grid on and even a legend! You can add these in the graph GUI that you’ve just seen, or do it through the command prompt

17 Labelling Axes: So let’s add a title, add a grid, label the axes and put up a legend.

18

19 grid puts a grid on the graph The spacing for the grid is automatically figured out by MATLAB title(‘…’) lets your graph have a title xlabel(‘…’), ylabel(‘…’) labels the x and y axes accordingly Put the labels inside the quotations Don’t forget the quotations ‘ ‘! legend(‘…’, ‘…’, …, ‘…’) produces a legend, labeling what each plot is on the graph By default, MATLAB takes all points and connects them with a solid line, and it’s got its own way of determining which colour belongs to what plot

20 Additional parameters for Graph Platting: In addition to the x and y points, you specify an additional parameter: plot(x, y, ‘line_style’); line_style is a character string of 2 characters The 1 st character specifies the colour of your plot The 2 nd character specifies how your plot will be plotted on the graph, or the plot style

21 Supported colours: blue, green, red, cyan, magenta, yellow, black Supported plot styles:

22 Examples: x = 0:0.1:10; y = x; plot(x,y,’g.’); This will plot a green line with dots at each point plot(x,y,’bo’); This will plot a blue line with circles at each point plot(x,y,'rx’); This will plot a red line with crosses at each point

Lab Task-03 X = [3 9 27]; % dependent vectors of interest Y = [10 8 6]; Z = [4 4 4]; t = [1 2 3]; % independent vector Plot these vectors in a single graph and embellish with custom colors. Also display legend of the graph.

Multiple plots in different Graph windows: the figure command can be used to display multiple plots in separate figure windows.

25 Multiple Graphs in One Window: There is also a way to produce multiple graphs in one window You can have more than 1 graph in one window at a time! Multiple plots can be displayed within a single figure window using the subplot function, which can be called as follows: subplot(rows, cols, whichArea) Each slot takes in a graph

26 How do we use the subplot command? subplot(m,n,p) or subplot(mnp) These determine the number of rows (m) and columns (n) for the amount of graphs you want p determines which location in the window you want the plot to go to The order is from left to right, top to bottom In order to properly use subplot, you must call this function first After, you code the syntax to plot something normally

27 Here’s a small example: If I wanted to make a window that has 4 plots, 2 plots in each row  2 rows, here’s what I’d do Do subplot(221)  Specify that we want to work on the top left corner Next, code the syntax to plot normally. The plot will appear on the top left corner Do subplot(222)  Specify that we want to work on the top right corner Next, code the syntax to plot normally. The plot will appear on the top right corner Do subplot(223)  Specify that we want to work on the bottom left corner Next, code the syntax to plot normally. The plot will appear on the bottom left corner Do subplot(224)  Specify that we want to work on the bottom right corner Next, code the syntax to plot normally. The plot will appear on the bottom right corner

Example: To plot rate in the top half of a figure and growth in the bottom half, rate= [ ]; growth = [ ]; figure; subplot(2,1,1); plot(rate) subplot(2,1,2); plot(growth)

Lab Task -04 y1=2x, y2=4x, y3=6x, y4=8x; x= -5:0.1:5; Plot all these 4 outputs on a single graph window. Mention x- label, y-label on each. And display your Roll no: on top of the graph window.