220 likes | 562 Views
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 Know how to read data into Matlab Know how to describe what you want to do with the data
E N D
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 Know how to read data into Matlab Know how to describe what you want to do with the data Know how to use Matlab to transform data into the form you want it in Know how to examine the output for accuracy
Syllabus Lesson 1: Reading Data In Lesson 2: Getting Data Out Lesson 3: "parsing", "batching", other manipulations of data Lesson 4: Formulas (your own and others) Lesson 5: Formulas again! Lesson 6: Plots, the basics Lesson 7:Plots, fun play with plots Lesson 8:Plots again! (graphics for publication quality) Lesson 9: Output again!
Course Materials Course Website: http://indra.uoregon.edu/~admin/mediawiki-1.13.4/index.php/Matlab_DIY_for_Beginners
Today's Lesson What does data look like? What should we be looking for? Organization Data Types How do we use that information? Memory Requirements for Data Picking the right data reading function
What does Data Look Like? What you can expect: .csv -->Comma Separated Values .tsv --> Tab Separated Values .txt --> Text data in some format Unfamiliar extension? Check the documentation http://filext.com/ --> File Extension Search
Data encoded in a CSV Trial,RT,Response,Expected1,423,1,12,547,2,13,579,2,24,324,2,15,446,1,1
Data Encoded in a TSV Trial RT Response Expected1 423 1 12 547 2 13 579 2 24 324 2 15 446 1 1
An example of a Data in a .txt File commas and white space were used to separate the rows and columns
Data Organization How is the data presented in the file? headers? data separators? white space comma tab data types? numbers? letters? mixture?
How does Matlab see data? data types? Numbers? Integers (whole numbers) Doubles (decimals included) letters? Characters (letter) Strings (sequences of letters) mixture? Characters (letter or number) Strings (sequences of letters and numbers) booleans? True = 1 False = 0
Workspace can help you identify what Matlab sees These all look like 0 to us but Matlab sees them differently
Memory Requirements for Data How much memory do particular types require? Integers - 1,2,4, or 8 bytes (Usually 4) Doubles - 8 bytes Strings - 2 bytes per character Booleans - 8 bytes Why do we care? Program Efficiency Memory Limitations within Matlab Limited Memory for the program Matlab's Contiguous Memory Need
Arraysand Cells • In Matlab, everything is an Array • An Array can only store one type of data • Cells hold other types • You can make an Array of Cells • A Matrix is an Array of Arrays • A Matrix must always be square
How to use what we've learned? Matlab has multiple data parsing functions. The one to use depends on data organization. Aside from headers, is there non-numerical data? Non-Numerical data requires textscan Do you want all the data in the file? Advanced arguments to the function The above points will be explored in Lesson 3
Data type determines how Matlab reads data 54301, 4578, 44478, 234 subj_01, male, 34, right csvread 23 45 67 89 dlmread textscan
First Step - Writing your first code Using the Matlab Editor Comments %This is a comment This is code Testing code in the Matlab Command Window Declaring a variable x = 1;
Opening a file from Matlab What you need: Name of the File Path to the File Filename: data.csv, collection.txt, subject117.tsv File Path: On Windows: C:\My Documents\Collection\ On Mac/Unix: /Users/default/Collection/
Declaring File Name and Path %Name of the File filename = 'L1_data.csv'; %Path to File filepath = 'C:\Desktop\Classwork\' ;
Opening that file %Name of the File filename = 'L1_data.csv'; %Path to File filepath = 'C:\Desktop\Classwork\' ; %Open the file for editing datafile = fopen([filename,filepath],'r');
Exercises 1) Write a matlab command to open one of your own data files 2) Use Matlab help. Search for “file formats” to see what type of files Matlab can read and what the command is for reading them. For extra experience: 1 -- Read up on the uigetfile command in Matlab help. 2 -- Figure out how to use this function to get the path and name of a file.