importing data into matlab · introduction we often want to import data into matlab this data can...

12
Importing Data into Matlab Jake Blanchard University of Wisconsin - Madison Spring 2008

Upload: others

Post on 26-Aug-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Importing Data into Matlab

Jake Blanchard

University of Wisconsin - Madison

Spring 2008

Page 2: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Introduction

We often want to import data into

Matlab

This data can be from a variety of

sources:

◦ Spreadsheets

◦ CSV files

◦ Other text files

◦ Movies (avi)

◦ Images (bmp, gif, jpg, png, tiff, etc.)

◦ Audio (wav, etc.)

Page 3: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Reading Excel Files

[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE)

A=xlsread('data.xls','Sheet1')

Page 4: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Import Wizard

File/Import Data…

Page 5: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Others

[A,D,H]=IMPORTDATA(FILENAME, DELIM,HLINE)

Uses filename to choose which “helper” to use to

import data into the variable A, delimiter into D,

and header line number into H

Page 6: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Example – Book1.xlsx

name hw 1 hw 2 final

john 10 8 18

jane 9 8 17

chris 10 9 19

carla 10 8 18

Page 7: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

[a,b,c]=xlsread('book1.xlsx') a =

10 8 18

9 8 17

10 9 19

10 8 18

b =

'name' 'hw 1' 'hw 2' 'final'

'john' '' '' ''

'jane' '' '' ''

'chris' '' '' ''

'carla' '' '' ''

c =

'name' 'hw 1' 'hw 2' 'final'

'john' [ 10] [ 8] [ 18]

'jane' [ 9] [ 8] [ 17]

'chris' [ 10] [ 9] [ 19]

'carla' [ 10] [ 8] [ 18]

Page 8: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

A=importdata('book1.csv',',',1)

A =

data: [4x3 double]

textdata: {5x4 cell}

Page 9: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

More…

>> A.data

ans =

10 8 18

9 8 17

10 9 19

10 8 18

Page 10: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

More

>> A.textdata

ans =

'name' 'hw 1' 'hw 2' 'final'

'john' [] [] []

'jane' [] [] []

'chris' [] [] []

'carla' [] [] []

Page 11: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

More general approaches

textscan

sscanf

fscanf

Page 12: Importing Data into Matlab · Introduction We often want to import data into Matlab This data can be from a variety of sources: Spreadsheets CSV files Other text files Movies (avi)

Questions?