preview - Preview eight rows from file using import options - MATLAB (original) (raw)

Main Content

Preview eight rows from file using import options

Syntax

Description

`T` = preview([filename](#d126e869613),[opts](#d126e869643)) returns a table containing the first eight rows of data infilename, using the import options opts.

example

Examples

collapse all

First, create an import options object. Next, use the import options to get the first eight rows of the table, and then generate a preview showing only the variables of interest.

Create an import options object for a file.

filename = 'outages.csv'; opts = detectImportOptions(filename);

Preview the table.

ans=8×6 table Region OutageTime Loss Customers RestorationTime Cause
___________ ____________________ ______ __________ ____________________ _________________

'SouthWest'    01-Feb-2002 12🔞00    458.98    1.8202e+06    07-Feb-2002 16:50:00    'winter storm'   
'SouthEast'    23-Jan-2003 00:49:00    530.14    2.1204e+05                     NaT    'winter storm'   
'SouthEast'    07-Feb-2003 21:15:00     289.4    1.4294e+05    17-Feb-2003 08:14:00    'winter storm'   
'West'         06-Apr-2004 05:44:00    434.81    3.4037e+05    06-Apr-2004 06:10:00    'equipment fault'
'MidWest'      16-Mar-2002 06🔞00    186.44    2.1275e+05    18-Mar-2002 23:23:00    'severe storm'   
'West'         18-Jun-2003 02:49:00         0             0    18-Jun-2003 10:54:00    'attack'         
'West'         20-Jun-2004 14:39:00    231.29           NaN    20-Jun-2004 19:16:00    'equipment fault'
'West'         06-Jun-2002 19:28:00    311.86           NaN    07-Jun-2002 00:51:00    'equipment fault'

Select which variables to include in the preview and read operations.

opts.SelectedVariableNames = {'Region','OutageTime'};

Preview the first eight rows and selected variables.

ans=8×2 table Region OutageTime
___________ ____________________

'SouthWest'    01-Feb-2002 12🔞00
'SouthEast'    23-Jan-2003 00:49:00
'SouthEast'    07-Feb-2003 21:15:00
'West'         06-Apr-2004 05:44:00
'MidWest'      16-Mar-2002 06🔞00
'West'         18-Jun-2003 02:49:00
'West'         20-Jun-2004 14:39:00
'West'         06-Jun-2002 19:28:00

Input Arguments

collapse all

Name of the file to read, specified as a character vector or a string scalar.

Example: 'myFile.xlsx'

Data Types: char | string

File import options, specified as anSpreadsheetImportOptions,DelimitedTextImportOptions orFixedWidthImportOptions object created by thedetectImportOptions function. The opts object contains properties that control the data import process. For more information on properties for individual objects, see the appropriate object page.

Algorithms

Version History

Introduced in R2018a