1 / 22

Matlab DIY

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

ally
Download Presentation

Matlab DIY

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matlab DIY Lesson 1: Reading Data

  2. 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

  3. 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!

  4. Course Materials Course Website: http://indra.uoregon.edu/~admin/mediawiki-1.13.4/index.php/Matlab_DIY_for_Beginners

  5. 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

  6. 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

  7. Data encoded in a CSV Trial,RT,Response,Expected1,423,1,12,547,2,13,579,2,24,324,2,15,446,1,1

  8. Data Encoded in a TSV Trial    RT    Response    Expected1    423    1    12    547    2    13    579    2    24    324    2    15    446    1    1

  9. An example of a Data in a .txt File commas and white space were used to separate the rows and columns

  10. Data Organization How is the data presented in the file? headers? data separators? white space comma tab data types? numbers? letters? mixture?

  11. 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

  12. Workspace can help you identify what Matlab sees These all look like 0 to us but Matlab sees them differently

  13. 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

  14. 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

  15. 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

  16. Data type determines how Matlab reads data 54301, 4578, 44478, 234 subj_01, male, 34, right csvread 23    45    67    89 dlmread textscan

  17. 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;

  18. 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/

  19. Declaring File Name and Path %Name of the File filename = 'L1_data.csv'; %Path to File filepath = 'C:\Desktop\Classwork\' ;

  20. 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');

  21. Questions?

  22. 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.

More Related