Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.

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

Plotting Selim Aksoy Bilkent University Department of Computer Engineering
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.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Input/Output Functions Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
Input/Output Functions Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
The textread Function It is designed to read ASCII files that are formatted into columns of data Each column can be of a different type It is useful for.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 11/03/2003.
Chapter 9 Above: An early computer input/output device on the IBM 7030 (STRETCH)
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
Introduction to Matlab 7 Part III 1Daniel Baur / Introduction to Matlab Part III Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
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()
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Cell Arrays 1.Definition 2.Creating Cell Arrays 3.Referencing Cell Arrays 4.Augmenting Cell Arrays 5.Use of Cell Arrays 1.
Introduction to File I/O High-Level Functions 1.Data files 2."High level" File I/O 3.dlmread() 4.xlsread() 1.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Matlab Training Session 10: Loading Binary Data Course Website: Training Sessions.htm.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
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)
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
Introduction to Scientific Programming in MATLAB Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction To Matlab Class 4 Instructors: Hristiyan (Chris) Kourtev and Xiaotao Su, PhD Double click the matlab icon When prompted click “Skip”
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Early File I/O To help you get started with your final project 1. Definition of “high level” 2. Is using a High Level function appropriate? 3. xlsread()
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Introduction to MATLAB ENGR 1181 MATLAB 1. MATLAB Built-in Math Functions  Pre-defined in MATLAB ready for use exp(x) – exponential (e x ) log(x) – natural.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
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.
FILE I/O: Low-level 1. The Big Picture 2 Low-Level, cont. Some files are mixed format that are not readable by high- level functions such as xlsread()
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
Input Output IO and datafiles Credits also to Prof Selim Aksoy (Bilkent University.
Reading and Writing Data Files
Working with files Saving and loading Matlab variables to and from .mat files does not require any special file handling, just use save() and load() However,
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.
Net 222: Communications and networks fundamentals (Practical Part)
Introduction to MATLAB
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)
Introduction to MATLAB Plotting LAB 3
Introduction to MATLAB
Introduction to MATLAB
Yang-Ming University, Taipei, Taiwan
Introduction to MATLAB
Plotting Signals in MATLAB
Introduction to MATLAB
Input/Output Functions
Introduction to Matlab
Input/Output Functions
Presentation transcript:

Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003

Overview for 10/29/2003 Brief review of topics covered in last session (10/29/2003) File Output MATLAB Scripts and Functions

Review for 10/27/2003 Plotting – in depth File input Wing’s birthday, or something.

Plotting Several types of plots available Plot Polar Bar Hist

Color options Color options: –Yellow - ‘y’ –Magenta - ‘m’ –Cyan - ‘c’ –Red - ‘r’ –Green - ‘g’ –Blue - ‘b’ –White - ‘w’ –Black - ‘k’ Example: plot(temp, ‘y’);

Line options Line styles: –- solid line (default) –-- dashed line –: dotted line –-. dash-dot line

Marker Options + - plus sign o - circle * - asterisk. - Point x - cross s - square d - diamond ^ - upward pointing triangle v - downward pointing triangle > - right pointing triangle < - left pointing triangle p - five-pointed star (pentagram) h - six-pointed star (hexagram)

Plot() (from MATLAB help) Linear 2-D plot Syntax: –plot(Y) –plot(X1,Y1,...) –plot(X1,Y1,LineSpec,...) –plot(...,'PropertyName',PropertyValue,...) –h = plot(...)

Plot() con’t: 2 MATLAB defaults to plotting a blue line between points Other options exist: –Different color lines –Different types of lines –No line at all!

Polar() Plot polar coordinates Syntax: –polar(theta,rho) –polar(theta,rho,LineSpec) Theta – Angle counterclockwise from the 3 o’clock position Rho – Distance from the origin

Polar() con’t: 2 Line color, style and markings apply as they did in the example with Plot().

Bar() Creates a bar graph Syntax –bar(Y) –bar(x,Y) –bar(...,width) –bar(...,'style') –bar(...,LineSpec)

Hist() Creates a histogram plot Syntax: –n = hist(Y) –n = hist(Y,x) –n = hist(Y,nbins)

High-Level File I/O I/O = input/output 3 important commands for input –csvread –dlmread –textread

csvread Read a comma-separated value file Syntax: –a = csvread('filename') –a = csvread('filename',row,col) –a = csvread('filename',row,col,range) Note – csvread does not like to read in text!

dlmread Like csvread, only instead of a comma, you specify the delimiter Syntax: –a = dlmread(filename,delimiter) –a = dlmread(filename,delimiter,R,C) –a = dlmread(filename,delimiter,range) Treat this like a generalized form of csvread.

textread Reads formatted data from a text file Syntax: –[A,B,C,...] = textread('filename','format') –[A,B,C,...] = textread('filename','format',N) –[...] = textread(...,'param','value',...) Ex. A = textread(‘blah.txt’, ‘%u%u’); Useful, but try to do without it, MATLAB is somewhat slower when dealing with text data

Delimiters Delimiter: A character or sequence of characters marking the beginning or end of a unit of data. Ex. 1,2,3 (the delimiter would be,) Also 1:2:3 (the delimiter would be :)

Delimiters, con’t: 2 The most common delimiter is a comma: hence the term csv or comma separated values. Microsoft Excel can read csv formatted files

High Level File Output Some of the input commands have corresponding high-level output commands csvwrite dlmwrite

csvwrite Write a matrix to a comma-seperated value file Syntax: –csvwrite('filename',M) –csvwrite('filename',M,row,col) Ex. csvwrite(‘blah.csv’,a);

dlmwrite Writes a matrix to a delimited file (using the delimiter you specify) Syntax: –dlmwrite(filename,M,delimiter) –dlmwrite(filename,M,delimiter,row,col) Ex. dlmwrite(‘blah.txt’,a,’:’);

Low-Level file I/O fopen fclose fprintf fgetl / fgets

fopen Opens a file and returns the handle to the file object File_ID = fopen(‘blah.txt’) Capturing the file handle is necessary to write or read to/from the file

fclose Closes a file associated with a specific file identification handle Ex. fclose(File_ID); Ex. fclose(‘all’);

fprintf Multi-use: can output to a file or a screen Ex. fprintf(fid,'%6.2f %12.8f\n',y); %6.2f means a floating point with 6 leading decimals and 2 trailing Specifying 1 instead of fid will output to the screen

fgetl / fgets Get line and get string, respectively. Fgetl will get you a line without the newline character at the end, while fgets will preserve the newline character (\n). Syntax: –Line = fgetl(File_ID); –Line = fgets(File_ID);

Programming in MATLAB Two types of files: –Scripts –Functions

MATLAB Scripts Scripts are MATLAB commands stored in text files. When you type the name of the script file at the MATLAB prompt the commands in the script file are executed as if you had typed them in from the keyboard. Scripts end with the extension.m Referred to as M-Files

MATLAB functions Have input and output parameters MATLAB can return more than one variable at the end of a function Variables in scope in the MATLAB function go out of scope and are eliminated when the MATLAB function ceases to exist.

MATLAB Functions More on function files tomorrow

End