MATLAB How to use (using M-files)

Slides:



Advertisements
Similar presentations
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.
Advertisements

Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
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.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
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.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Matlab intro The Environment
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
MATLAB Fundamentals.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
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()
MATLAB Plotting With MATLAB 1. Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called.
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.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Plot (x-values, y-values) >> x = linspace (-3, 3, 20); >> x = linspace (-3, 3, 20); >> y = 2*x – 1; >> y = 2*x – 1; >> plot (x, y) >> plot (x, y)
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
Introduction to Scientific Programming in MATLAB Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
ECE 1304 Introduction to Electrical and Computer Engineering
Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.
Release Numbers MATLAB is updated regularly
Introduction to Mat lab
Plotting Chapter 5.
Introduction to MATLAB
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Lecture 25: Exploring data
Matrices and Arrays.
MATLAB DENC 2533 ECADD LAB 9.
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB How to use (using M-files) Double click this icon
Use of Mathematics using Technology (Maltlab)
MATLAB How to use (using M-files) Double click this icon
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
Introduction to MATLAB Plotting LAB 3
Introduction to MATLAB
Plotting Signals in MATLAB
Part 1 Chapter 2 MATLAB Fundamentals
How to Use MATLAB A Brief Introduction.
Introduction to Matlab
Presentation transcript:

MATLAB How to use (using M-files) Search and open the current installed version of Matlab. Matlab updates twice a year with an ‘a’ and ‘b’ addition. Here we are using 2015b Open “MATLAB R2015b” Don’t open the Activate or Deactivate option

This is the interactive Matlab window that will appear.

Change the directory as shown: CLICK HERE CLICK on DESKTOP

How do you start a new M-file in MATLAB window. Do the following: File > New > M-file Click “HOME” Tab Click “New Script”

This is the panel that you get to type in your program (codes). The panels can be rearranged or made into separate windows.

Type in your program codes in this window.

Save your m-files by doing: * Indicated not yet saved Click on “EDITOR” tab Click on “Save” Set Directory, before we set the working directory to Desktop So save the file there as well Enter a filename Do not use spaces It will be saved as a “.m” file

You will have “sample_code.m” Saved to Desktop Directory is Desktop Shows folder the directory points to That now should have the saved file

After saving your M-file, you need to run it Click “EDITOR” tab Click “Run”

See error at Line 3 Fix typo from “cost” to “cos”

Re-run and a window will open up with the plot of the three functions, X,Y, Z. Notice that your graph has no title, use “help” command in the MATLAB window to learn how you can add title.

Type in “help plot” in the Command Window and hit enter

>> help plot   PLOT Linear plot. PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted. PLOT(Y) plots the columns of Y versus their index. If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)). In all other uses of PLOT, the imaginary part is ignored. Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 columns: b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star y yellow s square k black d diamond v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram

The rest of the results when you type “help plot”– read and learn. For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw any line. PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings. For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points. The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed in the table above for color systems where the default is blue for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems, PLOT cycles over the axes LineStyleOrder property. PLOT returns a column vector of handles to LINE objects, one handle per line. The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines. See also SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, GRID, CLF, CLC, TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT, STEM.   >>

Find out how you can use “title” command to add title to your figure. Type “help title” >> help title TITLE Graph title. TITLE('text') adds text at the top of the current axis. See also XLABEL, YLABEL, ZLABEL, TEXT.

After you learn how to use “title” command, use it in your program

See the result of using “title” command in your program

Simple Exercise: Run the following program, using the guidelines provided in earlier slides. Include title, xlabel, ylabel Use help command if necessary Show output on the monitor to your TA t=0:pi/100:2*pi; %comments start with percent sign '%' y=sin(t); %';' semicolons suppress the output z=cos(t); x=(cos(t)).^2; plot(t,y,t,z,t,x)