Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low.

Slides:



Advertisements
Similar presentations
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Advertisements

M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
A Guide to Unix Using Linux Fourth Edition
Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Using Excel to Analyze OSAT Results Download OSAT results from the internet Analyze results with formulae Create blank calculation pages Filter and copy.
Exploring Microsoft Excel 2002 Chapter 7 Chapter 7 List and Data Management: Converting Data to Information By Robert T. Grauer Maryann Barber Exploring.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
Chapter 7 Data Management. Agenda Database concept Import data Input and edit data Sort data Function Filter data Create range name Calculate subtotal.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 13 Strings and File I/O  Read Bishop, Chapter 9.  Lab #13 and Homework #13 due next week.
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.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
Topics Introduction Hardware and Software How Computers Store Data
Aloha Aloha What you see: What the computer sees: binary number columns binary number columns
Chapter 3 Mastering Editors
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 4.
File formats Wrapping your data in the right package Deanna M. Church
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Cell Arrays 1.Definition 2.Creating Cell Arrays 3.Referencing Cell Arrays 4.Augmenting Cell Arrays 5.Use of Cell Arrays 1.
File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
File I/O 1. Goals of this chapter 2. General Concept, lots of examples 3. High-level I/O 1. Built-in functions that do everything in one step 4. Low-level.
Introduction to File I/O High-Level Functions 1.Data files 2."High level" File I/O 3.dlmread() 4.xlsread() 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Matlab Training Session 10: Loading Binary Data Course Website: Training Sessions.htm.
Data Structure & File Systems Hun Myoung Park, Ph.D., Public Management and Policy Analysis Program Graduate School of International Relations International.
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2 – Gaining Proficiency: The Web and Business.
CMPS 1371 Introduction to Computing for Engineers FILE Input / Output.
File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room ,
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
XP Tutorial 8 Adding Interactivity with ActionScript.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
Chapter Three The UNIX Editors.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
EGR 115 Introduction to Computing for Engineers Formatted File Input / Output Wednesday 12 Nov 2014 EGR 115 Introduction to Computing for Engineers.
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.
Files Tutor: You will need ….
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
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()
1 CSC103: Introduction to Computer and Programming Lecture No 27.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 11”
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
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()
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
1.4 Representation of data in computer systems Character.
Topics Introduction Hardware and Software How Computers Store Data
Other Kinds of Arrays Chapter 11
Data File Import / Export
Advanced Data Import & Export Jeff Henrikson
Topics Introduction to File Input and Output
Topics Introduction Hardware and Software How Computers Store Data
funCTIONs and Data Import/Export
Introduction to MATLAB
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Topics Introduction to File Input and Output
Topics Introduction to File Input and Output
Presentation transcript:

Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low level file operations Explore spreadsheet I/O Explore text file I/O Topics Brief overview then Lots and lots of exercises! CHAPTER 14 - Mastering MATLAB

Fall 2006AE6382 Design Computing2 File Input and Output Reading from a source Writing to a destination

Fall 2006AE6382 Design Computing3 High Level File Input and Output The highest (most abstract) level of file I/O operations works with the entire MATLAB workspace, or with individual variables. EXERCISE: Review the HELP descriptions for save and load Create several variables Save them to disk Clear memory Load one of the variables Discuss some uses of these statements … >>save demo1 or >>load demo1 >>help save or >>help load

Fall 2006AE6382 Design Computing4 Features of High Level I/O The programmer thinks about save and retrieving entire sets of variables The programmer does not consider how the individual bytes are stored on disk The programmer does not consider how the variables are organized within the file There is not explicit “open” or “close” of the file stream, one simply “grabs” entire sets of variables from a file (or copies them to files).

Fall 2006AE6382 Design Computing5 Data Import and Export The next highest level of file I/O describing working with entire files, but whose contents are not explicitly MATLAB variables. For example, working with spreadsheets, images, audio and video files, or raw ASCII text. MATLAB provides numerous functions to help in working with these different formats. REFER to section 13.2 (pp. 206) >> help fileformats

Fall 2006AE6382 Design Computing6 Working with Text Files It is common to encounter files that contain columns and rows of numeric data –numbers have different precisions and formats –delimiters (spaces, tabs, ;) separate columns Command: dlmread - read data from a text file Examples: >> data = dlmread(‘demo.txt’,‘ ‘); >> [a,b] = dmsread(‘demo1.dat’,‘;’); >> help dlmread

Fall 2006AE6382 Design Computing7 Working with Spreadsheet Data Command: xlsread - read data from an Excel spreadsheet Examples: Exercise: Download example spreadsheet (DEMO.XLS) from web site Explore various forms of xlsread command How are data stored in MATLAB? What about column and row names? What about the formulas? Discuss how this routine can be incorporated into your home work assignment >> m = xlsread(‘demo.xls’); >> [a,b] = xlsread(‘demo.xls’); >> help xlsread

Fall 2006AE6382 Design Computing8 Low Level File I/O At the lowest level, the programmer is responsible for the moving the the bits and bytes. File streams are “opened” and “closed” Here is typical MATLAB code: What does this code do? Can you embed this code within a function to display contents of an “m-file?” >> j = fopen(‘proj3data.txt’); >> while (not(feof(j))) line = fgetl(j); disp(line); >> end; >> fclose(j); NOTE: See help iofun for a description of the different I/O functions

Fall 2006AE6382 Design Computing9 Low Level File I/O (2) Doing low level file I/O can get very tricky so you will have to read the documentation carefully if you use this approach! function listfile(filename) % demo of low level file I/O if ~ischar(filename) error('LISTFILE: argument must be filename') end if isempty(filename) error('LISTFILE: argument not defined') end fid=fopen(filename,'rt'); % open as text file for read only if fid==-1 error('LISTFILE: file not found or can''t be opened') end while not(feof(fid)) line = fgetl(fid); disp(line); end; fclose(fid);

Fall 2006AE6382 Design Computing10 Text File Vocabulary A file consists of many lines, each line is separated from the next by an invisible “newline” character –PC’s, Mac’s and Unix/Linux all use different newline chars –PC’s use “carriage return & linefeed” or CR/LF –Unix systems use LF and Mac’s use CR Each line (or record) can be subdivided into a series of “fields” or “columns” separated by a “field delimiter.” Different programs use different delimiters (e.g., spaces, commas, tabs, quotes, etc.) Numbers, etc. are actually stored in ASCII not binary, and must be translated back and forth.

Fall 2006AE6382 Design Computing11 Text file vocabulary Here is a sample from our text file: e e e e e e e e e e e e e e e+000

Fall 2006AE6382 Design Computing12 Encoding information on the computer ASCII American Standard Code for Information Interchange 1 character  1 byte Unicode the new standard 1 character  2-4 bytes Allows representing every character in a language (Chinese included!)

Fall 2006AE6382 Design Computing13 Exercise: working with text files Download text files ttimes.txt and atlanta.txt from web site. Try loading the data using various commands –load –dlmread –Import to a spreadsheet, then use xlsread into Matlab In atlanta.txt, each record represents a single line, with the 3,4,5 and 6 columns represent X1,Y1, X2 and Y2 points for that line. Write a program that plots each of these lines. What does the picture represent?

Fall 2006AE6382 Design Computing14 Optional exercise: working with text files The file ttimes.txt contains six columns: Row Id, Col Id, Point ID, X, Y, TT Load the file, View the first 10 rows - what do you notice? Enter >>format short g then view the data again Write a script to create a “PLAID” from X, Y and TT. The RowID and ColID can be used to position these data into a 25x25 matrix. Create a contour plot using the plaid Modify your script to overlay the lines (from atlanta.txt ) onto the contour.

Fall 2006AE6382 Design Computing15 Summary Action Items Review the lecture Use this to complete homework Review questions Describe basic concepts of file I/O. Compare and contrast high- versus low-level file I/O. Identify important elements of a text file Why use text files?

Fall 2006AE6382 Design Computing16 Important commands >> help iofun >> help fileformats >> help xlsread >> help dlmread >> help sprintf