_____
______
_____
3
3
1
3
2
2
1
1
3
Read Table from File
It is common to have a large quantity of tabular data in a file such as a CSV (comma-separated value)
file or an Excel® spreadsheet. To read such data into a table, use the readtable function.
For example, the CSV file outages.csv is a sample file that is distributed with MATLAB. The file
contains data for a set of electrical power outages. The first line of outages.csv has column names.
The rest of the file has comma-separated data values for each outage. The first few lines are shown
here.
Region,OutageTime,Loss,Customers,RestorationTime,Cause
SouthWest,2002-02-01 12:18,458.9772218,1820159.482,2002-02-07 16:50,winter storm
SouthEast,2003-01-23 00:49,530.1399497,212035.3001,,winter storm
SouthEast,2003-02-07 21:15,289.4035493,142938.6282,2003-02-17 08:14,winter storm
West,2004-04-06 05:44,434.8053524,340371.0338,2004-04-06 06:10,equipment fault
MidWest,2002-03-16 06:18,186.4367788,212754.055,2002-03-18 23:23,severe storm
...
To read outages.csv and store the data in a table, you can use readtable. It reads numeric
values, dates and times, and strings into table variables that have appropriate data types. Here, Loss
and Customers are numeric arrays. The OutageTime and RestorationTime variables are
datetime arrays because readtable recognizes the date and time formats of the text in those
columns of the input file. To read the rest of the text data into string arrays, specify the "TextType"
name-value argument.
outages = readtable("outages.csv","TextType","string")
outages=1468×6 table
Region
OutageTime
Loss
Customers
RestorationTime
Cause
___________
________________
______
__________
________________
______________
"SouthWest"
2002-02-01 12:18
458.98
1.8202e+06
2002-02-07 16:50
"winter storm"
"SouthEast"
2003-01-23 00:49
530.14
2.1204e+05
NaT
"winter storm"
"SouthEast"
2003-02-07 21:15
289.4
1.4294e+05
2003-02-17 08:14
"winter storm"
"West"
2004-04-06 05:44
434.81
3.4037e+05
2004-04-06 06:10
"equipment fau
"MidWest"
2002-03-16 06:18
186.44
2.1275e+05
2002-03-18 23:23
"severe storm"
"West"
2003-06-18 02:49
0
0
2003-06-18 10:54
"attack"
"West"
2004-06-20 14:39
231.29
NaN
2004-06-20 19:16
"equipment fau
"West"
2002-06-06 19:28
311.86
NaN
2002-06-07 00:51
"equipment fau
"NorthEast"
2003-07-16 16:23
239.93
49434
2003-07-17 01:12
"fire"
"MidWest"
2004-09-27 11:09
286.72
66104
2004-09-27 16:37
"equipment fau
"SouthEast"
2004-09-05 17:48
73.387
36073
2004-09-05 20:46
"equipment fau
"West"
2004-05-21 21:45
159.99
NaN
2004-05-22 04:23
"equipment fau
"SouthEast"
2002-09-01 18:22
95.917
36759
2002-09-01 19:12
"severe storm"
"SouthEast"
2003-09-27 07:32
NaN
3.5517e+05
2003-10-04 07:02
"severe storm"
"West"
2003-11-12 06:12
254.09
9.2429e+05
2003-11-17 02:04
"winter storm"
"NorthEast"
2004-09-18 05:54
0
0
NaT
"equipment fau
⋮
9 Tables
9-6
Précédent

- 350/1450

Suivant