Matlab DIY Lesson 3: Parsing data. Today's Lesson “ parse ” = analyze into its parts o Sort the data you want MATLAB to use o Designate different segments.

Slides:



Advertisements
Similar presentations
The essentials managers need to know about Excel
Advertisements

Database Basics. What is Access? Database management system Computer-based equivalent of a manual database Makes it easy to organize and update information.
CC SQL Utilities.
1) Terms to Know 2) Starting an Office 97 Application 8) Finding a missing file 7)File Managment 4) Utilizing the Right Mouse Button 6) Using Help 3)
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Loading Excel Double click the Excel icon on the desktop (if you have this) OR Click on Start All Programs Microsoft Office Microsoft Office Excel 2003.
Understanding Microsoft Excel
Viewing and using data from a SonoBatch run. SonoBatch processing generates tab-delimited text files readable as spreadsheets. To open in Excel, select.
Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Matlab DIY Lesson 1: Reading Data. Purpose of this Seminar Basic Ability to handle Data Analysis and Presentation in Matlab Understand how data is organized.
Lesson 2: Basic Output You’ve got data……now what???
Lesson 2: Basic Output You’ve got data……now what???
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Input/Output Functions Selim Aksoy Bilkent University Department of Computer Engineering
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.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Lesson 1 – Microsoft Excel The goal of this lesson is for students to successfully explore and describe the Excel window and to create a new worksheet.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
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.
October 2003Bent Thomsen - FIT 3-21 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Lesson No:9 MS-Word Tools, Mail Merge and working with Tables CHBT-01 Basic Micro process & Computer Operation.
Mail merge letters are used to send the same or similar documents to many different people. Since they contain the recipient’s name, address, and other.
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
1 Data List Spreadsheets or simple databases - a different use of Spreadsheets Bent Thomsen.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 1 Introduction.
Colleague, Excel & Word Best of Friends Presented by: Joan Kaun & Yvonne Nelson College of the Rockies.
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.
Computer Information Technology – Section 4-12 Some text and examples used with permission from: Note: We not endorsing or promoting.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
5 1 Data Files CGI/Perl Programming By Diane Zak.
CCS – Mail Merge Mail Merge This presentation is incomplete without the associated discussion 1 Coloma Community Schools In-service 21 March 2014.
McGraw-Hill Technology Education © 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Office Access 2003 Lab 2 Modifying a Table and Creating.
Lesson 1 – Microsoft Excel * The goal of this lesson is for students to successfully explore and describe the Excel window and to create a new worksheet.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Working with Data Lists.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Files Tutor: You will need ….
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
Overview Excel is a spreadsheet, a grid made from columns and rows. It is a software program that can make number manipulation easy and somewhat painless.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Microsoft® Excel Create an Excel table. 1 Work with the Table Tools Design tab. 2 Sort and filter records in a table. 3 Identify structured references.
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()
Understanding Microsoft Excel Lesson 1 – Microsoft Excel 2013.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
Exporting & Formatting Budgets from FlexGen, NextGen & Zortec into Excel.
For Datatel and other applications Presented by Cheryl Sullivan.
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()
Perform a complete mail merge Lesson 14 By the end of this lesson you will be able to complete the following: Use the Mail Merge Wizard to perform a basic.
Understanding Microsoft Excel
Understanding Microsoft Excel
Understanding Microsoft Excel
Microsoft Excel A Spreadsheet Program.
Data File Import / Export
Intro to PHP & Variables
Understanding Microsoft Excel
Jeff Henrikson Lecture 11 Data Import & Export Jeff Henrikson 1.
Advanced Data Import & Export Jeff Henrikson
Learning about Taxes with Intuit ProFile
Lecture 2 Introduction to MATLAB
Learning about Taxes with Intuit ProFile
Spreadsheet/Worksheet
Note on Indexing of Array Elements
Stata Basic Course Lab 2.
Understanding Microsoft Excel
Bent Thomsen Institut for Datalogi Aalborg Universitet
Tutorial 8 Sharing, Integrating, and Analyzing Data
Presentation transcript:

Matlab DIY Lesson 3: Parsing data

Today's Lesson “ parse ” = analyze into its parts o Sort the data you want MATLAB to use o Designate different segments of the data o Tell MATLAB to do different things with different parts of the data “ batch ” = process a group of records as a single unit (one command processes multiple files)

Why Parse? Let's look at a few example files: - data output may not be in evenly spaced rows - you might be interested in a subset of the data and want to separate it from the rest - you might want to run different analysis on different parts of the data

Your first.m program During previous lessons you typed individual commands and entered them in the command window.m allows you to access a series of commands by entering the name of the program in the command window Open MATLAB  set current directory  open current directory window  double click on L3_csvread_pc.m

L3_csvread_pc.m review commands from previous lessons

Parse option 1: choose rows and columns of data where Matlab begins to read data Reading in the data file data = csvread([inpath,infilename],1,1); tsvread xlsread dlmread These all read in numbers NOT text 0,0 = first cell in upper left corner 1,0 = can be used to eliminate header data 10,5 = starts reading on 10 th line, 5 th column

Common csvread errors >> d = csvread([inpath,filename],1,0); ??? Error using ==> csvread Filename must be a string. Step 1: see what Matlab thinks filename is: 1) type filename in command window 2) check class of filename in workspace Step 2: adjust so that Matlab sees filename as a string 1) redefine filename variable by adding ‘’ or [] 2) type filename{1} this turns it into a string d=csvread([inpath,filename{1}],1,0);

Common csvread errors >> u = csvread([inpath,filename{1}],10,0); ??? Error using ==> csvread File not found. Step 1: check the path -is the name what you think it is? -have you been consistent in spelling for inpath and filename? Step 2: check your data file -have you used the right name? -should it be in a folder? -have you used the right suffix? u = csvread([data_inpath,filename{1}],10,0);

Common csvread errors >> c = csvread([data_inpath,filename{1}],0,0); ??? Error using ==> textscan Mismatch between file and format string. Trouble reading number from file (row 1, field 1) ==> time, Step 1: open data file and check for letters in the data Step 2: adjust to avoid problem area --adjust where Matlab begins reading or --adjust organization of the file

Parse option #2 Create a new smaller array with a subset of data >> c = csvread([data_inpath,filename{1}],1,1); >> k = csvread([data_inpath,filename{1}],2:8,1:10); ??? Error using ==> textscan Header lines must be a scalar integer. Error in ==> csvread at 45 m=dlmread(filename, ',', r, c); >> k = c(2:8,1:10);

Parse option #3: Naming segments of the data x_pos=data(:,1); y_pos=data(:,2); z_pos=data(:,3); mus1=data(:,4); mus2=data(:,5); mus3=data(:,6); event=data(:,7); time=data(:,8); %notice that we started reading the data at 1,1 so the file data is missing the first row and first column, each of these column numbers have been adjusted accordingly

Now you can perform simple formulas mn_x=mean(x_pos); SD_y=std(y_pos); Two ways to find more info on abbreviations for mathematical functions 1) command window >>help mean 2) Go to Matlab help and search for mean

Parse option #4: create program to select a subset of data onstamp=find(event>4); ontime=onstamp(1); offstamp=find(event<0); offtime=offstamp(1); mv_time=(offtime-ontime)*1/84; %sampling rate =84Hz eyes_open=data(ontime:offtime,:); %this creates a subset of data from rows that begin with event onset and end with event offset, the : means all columns are included subset of rows all columns

Printing Data to a File outfilename=[date,'L3_output.csv']; out_fid=fopen([outpath,outfilename],'w'); fprintf(out_fid,'filename,mn_x,std_y,mv_time,mn_x_EO\n'); fprintf(out_fid,'%s,%s,%s,\n',infilename,mn_x,SD_y,);

%Outputting just a String, useful for Headers. fprintf(out_fid,‘filename,mn_x, SD_y,\n'); %Outputting data from variables. fprintf(out_fid, '%s,%s,%s\n', filename,mn_x, SD_y,); Format specifier for how information is to be written, %s= string %d= decimal %f=fixed point decimal Look these up by typing “ help fprintf” Values to go in spaces L3.m

Special Characters you will likely use: \n = The newline character \t = The tab character \\ = The backslash character fprintf(out_fid, '%s,%s,%s\n', subj_num,group,AP_RMS); fprintf(out_fid, '%s\t%s\t%s\n', subj_num,group,AP_RMS); '\n'?

fprintf(out_fid, '%s,%f,%5.3f,,/n', filename, mn_x,MT,); fprintf(out_fid, '%g,%g,/n', eyes_open(1,:), eyes_open(2,:)); Output per data set One line vs. multiple lines Single variable output entire column of data from an array

Run the.m file 1)Save any changes to.m program 2)Type the name of the program (but not.m) in command window 3)Enter 4)Did you get any errors? 5)Did you get any messages at all? 6)Check your workspace 7)Are all your variables in place? 8)Check your desktop files 9)Did Matlab create an output folder? 10)Did Matlab create any output files? 11)Open the files 12)Do they look correct? 13)Which number specifier do you want to use? f, g, e, d?

Reading data with textscan infile=[inpath,infilename]; fid=fopen(infile,'r') ; if fid == -1 [infile,' could not be opened'] return end d=textscan(fid, '%s', 'delimiter', '\n'); %scans textfile and loads up as a string, delimiter chops it by each new line fclose(fid); %line above read in contents and stored it in "d", d is array of all info line by line textlines=d{1}; %this puts a wrapper on the data, begins with the first piece that is my data set

Creating a data array with textscan for p=2:length(textlines) herenow=strread(textlines{p},'%s','delimiter',',');%grabs the text lines and reads the whole line kind of turns it into csv with text) for q=1:length(herenow) big_array((p-1),q)=herenow(q); %(i-1) so it creates the new file from row 1 otherwise have a blank where old labels were end end

Creating data columns with textscan subj_num = cell2mat(big_array(:,1)); x_pos_t= str2num(cell2mat(big_array(:,2)));

Processing multiple data files Open L3_combine_batch_textscan.m This is a template file It is not set up to work on a current data set It has multiple inpaths to combine different files It has multiple subj_nums to allow batch processing

inroute='/Users/saavedra/Desktop/CP_eye_hand/key_variables/'; inroute2='/Users/saavedra/Desktop/CP_eye_hand/left_overs/'; outroute='/Users/saavedra/Desktop/CP_eye_hand/data_combine/'; if exist(outroute)==0 mkdir(outroute); end subj_num={'u11','t04','t19',};%creates an array with 1 row and a cell with a string for each subject name, you must have a folder for each subject for subj_index=1:length(subj_num)%creates an index of all the subjects inpath=cell2mat([inroute,subj_num(subj_index),'/']);% creates a string with subjnum imbedded infilename=cell2mat([subj_num(subj_index),'results.csv']); %creates an infilename with subj_num imbedded Processing multiple files

Counting is critical for output files Play with some common things that create weirdness in your output file 1) More headers than variables 2) Less headers than variables 3) More % s (or d or f) than variables 4) Put less %s than variables 5) Take the /n off the end of fprintf on data file Practice making errors

Open one of your own data files Label and sort data Keep records of the error messages Bring a record of errors to class Bring solution if you found it IF you did NOT find solution please send the error to Wayne and Sandy before 10 am Monday morning. Practice opening files