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()

Slides:



Advertisements
Similar presentations
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Advertisements

Excel Objects, User Interface, and Data Entry. ◦ Application Window  Title Bar  Menu Bar  Toolbars  Status Bar  Worksheet Window  Worksheet Input.
Objectives 1.Identify the functions of a spreadsheet 2.Identify how spreadsheets can be used. 3.Explain the difference in columns and rows. 4.Locate specific.
Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Managing Grades with Excel Viewing Help To view Help 1.Open Excel on your computer. 2.In the top right hand corner of the Excel Screen type in the.
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 Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
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.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
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.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Chapter 2: Working with Data in a Project
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
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.
Presenting results to the USER in a professional manner 1. semicolon, disp(), fprintf() 2. Placeholders 3. Special characters 4. Format-modifiers Output.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
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.
1 Performing Spreadsheet What-If Analysis Applications of Spreadsheets.
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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Lecture 13 File Input/Output From Chapter 8. Outline 8.1 Concept: Serial Input and Output (I/O) 8.2 MATLAB Workspace I/O 8.3 High-level I/O Functions.
Using Client-Side Scripts to Enhance Web Applications 1.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
 Agenda: 4/24/13 o External Data o Discuss data manipulation tools and functions o Discuss data import and linking in Excel o Sorting Data o Date and.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
FILE I/O: Low-level General Ideas. High vs. low-level Opening a file
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.
Logical Ops on Arrays Saving time / avoiding loops 1. Logical Operators 2. Logical Operations 3. Examples: numbers and letters 11.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Asking the USER for values to use in a software 1 Input.
5 1 Data Files CGI/Perl Programming By Diane Zak.
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.
Asking the USER for values to use in a software 1 Input.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Lecture 6: Output 1.Presenting results in a professional manner 2.semicolon, disp(), fprintf() 3.Placeholders 4.Special characters 5.Format-modifiers 1.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Use SPSS for solving the problems Lecture#21. Opening SPSS The default window will have the data editor There are two sheets in the window: 1. Data view2.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
An Introduction to Programming in Matlab Emily Blumenthal
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()
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,
IMPORTING AND EXPORTING DATA
Chapter 2: Getting Data into SAS
Functions (subprograms)
Advanced Data Import & Export Jeff Henrikson
Click ‘browse’ to search your device for
IPC144 Introduction to Programming Using C Week 8 – Lesson 1
funCTIONs and Data Import/Export
Introduction to MATLAB
Working With Data.
Presentation transcript:

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() 4. xlswrite() 5. dlmread() 6. dlmwrite() 1

1. Definition A file I/O function is considered HIGH-LEVEL if in ONE SINGLE COMMAND, it 1. Opens the file 2. Grabs the data 3. Stores it in variables 4. Closes the file High-level functions can be used to: 1. Load data from external sources (INPUT) 2. Save data back to a file (OUTPUT) 2

2. Wait.wait.wait… Before you decide if using a high level function is possible, evaluate the following: 1. What type of file is it? (Excel, text, jpg..) 2. Find the organization overall (data in rows, or data in columns, data placed all over the place…) 3. Recognize the delimiters (space, tabs, new lines, -, :, / any specific symbol. What makes it obvious it is a new column? What makes it obvious it is a new row?) 4. Recognize the data types (all numerical? all strings? Or combination of both) 3

2. Can High Level be used? 4

2. Can High Level be used? cont. “Neatly Organized” 1. Rows and Columns are “identifiable” 2. No “holes” anywhere 3. Always the same patterns per line 4. There is no mixes of delimiters (commas, spaces, tabs, dash.. ) 5

Questions Can these files be read using a high level function? 6

Answers Can these files be read using a high level function? 7 Yes Mixes of – and spaces. Mixes of, and spaces. Yes. White space only. Decimals are ok.

The input files (.txt,.xls,.xlsx,.m) should all be in the same directory for function calls to work! 8

2. Can High-Level be used? 9

3. xlsread() F1, help. The most general form is: Other calls possible: 10

3. xlsread() F1, help. The most general form is: Other calls possible: 11 How do we work with all this?

Example: xlsread() Reading from a grade book %load data from file [values text raw] = xlsread('grades.xlsx'); 12 Test. See results!

Example: xlsread() Reading from a grade book %load data from file [values text raw] = xlsread('grades.xlsx'); 13 Test. See results! Note that we are collecting multiple values using an array!

Results 14

3. xlsread(), cont. txt = nbs = 'Name' 'Age' 'Grade' 'Fred' '' '' 'joe' '' '' 'SaLLy' '' '' 'CharliE' '' '' 'mary' '' '' 'Ann' '' '' raw = 'Name' 'Age' 'Grade' 'Fred' [ 19] [ 78] 'joe' [ 22] [ 83] 'SaLLy' [ 98] [ 99] 'CharliE' [ 21] [ 56] 'mary' [ 23] [ 89] 'Ann' [ 19] [ 51] >> [txt nbs raw] = xlsread('grades.xlsx‘)   Variable names are up to the programmer. If named badly by mistake… BAD. The order of the return values is important.

3. xlsread(), cont. Simply omit the 2 nd and 3 rd return value to collect only numerical values. values = xlsread(‘grades.xlsx’); 16

3. xlsread(), cont. Simply omit the 2 nd and 3 rd return value to collect only numerical values. values = xlsread(‘grades.xlsx’); If a project needs all the data together, collect the 1 st and 2 nd return values into a dummy variable. [trash trash data] = xlsread(‘grades.xlsx’); 17

3. xlsread(), cont. Simply omit the 2 nd and 3 rd return value to collect only numerical values. values = xlsread(‘grades.xlsx’); If a project needs all the data together, collect the 1 st and 2 nd return values into a dummy variable. [trash trash data] = xlsread(‘grades.xlsx’); If there happen to be ‘holes’ in the spreadsheet, MATLAB fills it with a NaN value (not a number). The function isnan() can help determine where those ‘holes’ are. 18

3. xlsread(), cont. This function will not work under Citrix, since Excel is not installed on Citrix. Come to the lab to do labs and homework. 19 

4. xlswrite() Arrays can also be written to excel sheets: xlswrite(,,, ) The and arguments are optional. 20 clc clear %create phony data table = rand(5,3)*100; %print to excel xlswrite('testingTesting.xls',table)

2. Can High-Level be used? 21 NUMBERS ONLY.

5. Using Delimiters Rows are delimited by the new line character (enter key, invisible to the human eye). Columns are delimited by the same delimiter each time: Default delimiters: commas, and white space Other delimiters: any other symbol : - / F1 = help 22

5. Using Delimiters, cont. Delimiter: white space (spaces, or tabs) 23 Missing data is filled by zeros.

5. Using Delimiters, cont. Delimiter: commas Added feasibility to ‘skip’ columns 24

5. Using Delimiters, cont. Delimiter: other than the defaults 25 Specify the delimiter as the 2 nd argument.

5. Using Delimiters, cont. Delimiter: other than the defaults 26 Specify the delimiter as the 2 nd argument.

5. Using Delimiters, cont. "Neatly Organized" is important. 27 BAD RESULTS. Two delimiters (spaces and colons) in the file. Matlab is lost.

dlmwrite() M = [2, 123; 87, 4]; dlmwrite('test.txt', M, ','); File contains: 2,123 87,4 EXCEPT… 28

dlmwrite() By default, dlmwrite() saves files using Unix line endings – so if you look at the file in Notepad: This is not “wrong” – just different. This can be changed by setting the “newline” attribute when you call the function: dlmwrite('test.txt', M, ',', 'newline', 'pc'); 29