File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.

Slides:



Advertisements
Similar presentations
Slide No. 1 Chapter 1, Unit c Relative vs. Absolute Addressing in a Spreadsheet H Spreadsheet Address H Relative Address H Absolute Address H Examples.
Advertisements

Basics Of Spreadsheets Chapter Spreadsheet spreadsheet: grid of cells, each of which can contain text data or numeric data.
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.
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
1. Definition 2. Creating Cell Arrays 3. Augmenting Cell Arrays 4. Referencing Cell Arrays 5. Special case 6. Spreadsheets 1.
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.
 Cut and paste sometimes works  More likely want to go to temp sheet  Get it in any way you can  AND THEN clean it up.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
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.
Chapter 2 Querying a Database
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.
FIRST COURSE Excel Lecture. XP 2 Introducing Excel Microsoft Office Excel 2007 (or Excel) is a computer program used to enter, analyze, and present quantitative.
UNIX Filters.
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.
Create Mailing Labels (Word 2007) Word 2007 using the Mail Merge function and an Excel spreadsheet Create mailing labels from Member Rosters in.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
AN ENGINEER’S GUIDE TO MATLAB
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
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
Coding for Excel Analysis Optional Exercise Map Your Hazards! Module, Unit 2 Map Your Hazards! Combining Natural Hazards with Societal Issues.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
ARRAY REFERENCING 1 1. II. Array Referencing Assume an array has values. It is useful to “refer to” the elements contained within it – as smaller portions.
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.
Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 1 by Mary Anne Poatsy, Keith Mulbery, Lynn Hogan, Amy Rutledge, Cyndi Krebs, Eric.
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 13 Creating a Workbook Part 1. Learning Objectives Understand spreadsheets and Excel Enter data in cells Edit cell content Work with columns and.
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.
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.
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.
1 By: Nour Hilal. Microsoft Access is a database software where data is stored in one or more Tables. A Database is a group of related Tables. Access.
WEEK 11 Database Design. TABLE INSTANCE CHARTS Create Tables.
1 Chapter 3 Arrays (2) 1. Array Referencing 2. Common Operations 1. Slicing 2. Diminution 3. Augmentation 3. List of Commonly Used Built-in Functions 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.
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.
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.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
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.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
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.
Paper 2 – Exam Tips Unit 14 – Spreadsheets - Formatting Merging Cells: Tip: Merging Cells 1.Highlight the cells you want to merge 2.Click on the Merge.
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()
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.
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()
IMPORTING AND EXPORTING DATA
Chapter 2: Getting Data into SAS
Functions (subprograms)
Advanced Data Import & Export Jeff Henrikson
funCTIONs and Data Import/Export
Introduction to MATLAB
Working With Data.
Presentation transcript:

File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 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.

Whatever you do, 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() Name who has the highest grade! %load data from file [values text raw] = xlsread('grades.xlsx'); %find the position of the maximum grade %find whose name is associated with that position 12 Test. See results!

Results 13

Results To find the highest grade, work on the array values. To find the name, either use text or raw ! 14

Example: xlsread() Name who has the highest grade! %load data from file [values text raw] = xlsread('grades.xlsx'); %find the position of the maximum grade [trash row]= max(values(:,2)); %find whose name is associated with that position name = text{row+1,1}; %+1 due to headers fprintf('%s got the highest grade\n', name) 15

Example: xlsread() Name who has the highest grade! %load data from file [values text raw] = xlsread('grades.xlsx'); %find the position of the maximum grade [trash row]= max(values(:,2)); %find whose name is associated with that position name = text{row+1,1}; %+1 due to headers fprintf('%s got the highest grade\n', name) 16

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’); 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 happens 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.

Wrapping Up One command opens, loads, and closes the file. Before anything, look in the file, and decide whether a high-level function is appropriate xlsread(), dlmread() are common. There are many other high-level functions. The variables are automatically created by MATLAB. Sometimes as regular array [ ] Other times as cell array{ } Use knowledge from previous chapter to analyze the data in the arrays. FOR loops, A(position), A(row,col), A{row,col}, max(arrayName), mean(arrayName), sort(..), slicing, deleting, augmenting… 28