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
.
- The value of the
SelectedVariableNames
property of the import options objectopts
selects the variables that appear in the tableT
. - The preview function returns a subset of the data that the
readtable
function returns with the import options objectopts
. - Usually, the output of the
preview
function contains eight rows of data. However, in some instances the number of rows differs depending on property values defined in the import options objectopts
. For more details see, Tips.
Examples
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
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
The
preview
function returns fewer than eight rows in these cases:- When the file contains fewer than eight rows of data.
- When the
DataLines
or theDataRange
properties of theopts
object specify less than eight rows. - When a combination of the properties of the
opts
object result in less than eight rows of data. For example,preview
returns less than eight rows when the value of theEmptyLineRule
,ImportErrorRule
or theMissingRule
of theopts
object causes the importing function to omit data.
When the
DataLines
or theDataRange
property of theopts
object specifies multiple row ranges and the first row range spans fewer than eight rows, thenpreview
returns the rows from the first row range followed by rows from successive row ranges until it reaches a total of eight rows.
Version History
Introduced in R2018a