Review – Importing Data from Multiple Files

A datastore is a reference to a file or set of files. The datastore function informs where to find the files.

CodeDescription
ds = datastore(filename)Reference a single file
ds = datastore(directory)Reference a folder of files
data = read(ds)Read data incrementally
data = readall(ds)Read all data referenced in datastore

If your data isn’t formatted the way datastore expects, you can set the datastore properties. Examples of common properties are shown below. You can find all the properties in the the documentation.

>> ds = datastore(filename,"Delimiter","-","TextscanFormats","%D%C%f","SelectedVariableNames",var)
dsReference to a collection of data.
filenameFile location.
"Delimiter","-"Delimiter is one or more characters that separate data values in the file.
"TextscanFormats","%D%C%f"Import variables using the output class in the format specification string.
"SelectedVariableNames",varImport only the variables listed in var.

Merging Data

Once you read in multiple tables, you may want to join them together. You can join two tables in many ways. The various join functions are listed in the table below.

FunctionExample
join

Key1 in Tright must have unique values and contain every key in Tleft.
innerjoin
outerjoin

Two key variables are created.
outerjoin with "MergeKeys" on