Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

TabularTextDatastore

Datastore for tabular text files

Description

TabularTextDatastore objects are associated with collections of text files containing column-oriented or tabular data. Tabular data is data that is arranged in a rectangular fashion with each row having the same number of entries. To create a TabularTextDatastore object, you can use the tabularTextDatastore function or the datastore function. TabularTextDatastore properties specify how data is formatted in the files, and how you want to access the data.

Creation

Create TabularTextDatastore objects using the tabularTextDatastore function or the datastore function.

Properties

TabularTextDatastore PropertiesAccess and modify TabularTextDatastore properties

Object Functions

hasdataDetermine if data is available to read
numpartitionsNumber of datastore partitions
partitionPartition a datastore
previewSubset of data in datastore
readRead data in datastore
readallRead all data in datastore
resetReset datastore to initial state

Examples

expand all

Create a datastore from the sample file airlinesmall.csv, which contains tabular data.

ds = tabularTextDatastore('airlinesmall.csv','TreatAsMissing','NA');

View the variables in the datastore.

ds.VariableNames
ans = 1x29 cell array
  Columns 1 through 5

    {'Year'}    {'Month'}    {'DayofMonth'}    {'DayOfWeek'}    {'DepTime'}

  Columns 6 through 9

    {'CRSDepTime'}    {'ArrTime'}    {'CRSArrTime'}    {'UniqueCarrier'}

  Columns 10 through 13

    {'FlightNum'}    {'TailNum'}    {'ActualElapsedTime'}    {'CRSElapsedTime'}

  Columns 14 through 18

    {'AirTime'}    {'ArrDelay'}    {'DepDelay'}    {'Origin'}    {'Dest'}

  Columns 19 through 22

    {'Distance'}    {'TaxiIn'}    {'TaxiOut'}    {'Cancelled'}

  Columns 23 through 25

    {'CancellationCode'}    {'Diverted'}    {'CarrierDelay'}

  Columns 26 through 28

    {'WeatherDelay'}    {'NASDelay'}    {'SecurityDelay'}

  Column 29

    {'LateAircraftDelay'}

Modify the SelectedVariableNames property to specify the variables of interest.

ds.SelectedVariableNames = {'Year','Month','Cancelled'};

Alternatively, you can specify the variables of interest when you create the datastore.

ds = tabularTextDatastore('airlinesmall.csv','TreatAsMissing','NA','SelectedVariableNames',{'Year','Month','Cancelled'});

Create a datastore from the sample file airlinesmall.csv, which contains tabular data.

ds = tabularTextDatastore('airlinesmall.csv','TreatAsMissing','NA');

Specify the variables of interest.

ds.SelectedVariableNames = {'Year','Month','UniqueCarrier'};

View the SelectedFormats property.

ds.SelectedFormats
ans = 1x3 cell array
    {'%f'}    {'%f'}    {'%q'}

The SelectedFormats property indicates that the Year and Month variables will be interpreted as columns of floating-point values, and the UniqueCarrier variable will be interpreted as a column of text.

Specify that the first two variables should be read as signed integers, and the third variable should be read as a categorical value by modifying the SelectedFormats property.

ds.SelectedFormats = {'%d','%d','%C'};

Preview the data.

T = preview(ds)
T=8x3 table
    Year    Month    UniqueCarrier
    ____    _____    _____________

    1987    10       PS           
    1987    10       PS           
    1987    10       PS           
    1987    10       PS           
    1987    10       PS           
    1987    10       PS           
    1987    10       PS           
    1987    10       PS           

Introduced in R2014b

Was this topic helpful?