Syntax Show
Descriptionexample
For files containing mixed numeric and text data, example
To set specific import options for your data, you can either use the
Examplescollapse all Read Matrix from Text FileDisplay
the contents of 6,8,3,1 5,4,7,3 1,6,7,10 4,2,8,2 2,7,5,9 M = readmatrix('basic_matrix.txt') M = 5×4
6 8 3 1
5 4 7 3
1 6 7 10
4 2 8 2
2 7 5 9
Read Matrix from Spreadsheet FileImport numeric data from M = readmatrix('basic_matrix.xls') M = 5×4
6 8 3 1
5 4 7 3
1 6 7 10
4 2 8 2
2 7 5 9
Read Matrix from Specified Sheet and Range Using Import OptionsPreview the data from a spreadsheet file and import numerical data as a matrix from a specified sheet and range. The spreadsheet file opts = detectImportOptions('airlinesmall_subset.xlsx'); preview('airlinesmall_subset.xlsx',opts) ans=8×29 table
Year Month DayofMonth DayOfWeek DepTime CRSDepTime ArrTime CRSArrTime UniqueCarrier FlightNum TailNum ActualElapsedTime CRSElapsedTime AirTime ArrDelay DepDelay Origin Dest Distance TaxiIn TaxiOut Cancelled CancellationCode Diverted CarrierDelay WeatherDelay SDelay SecurityDelay LateAircraftDelay
____ _____ __________ _________ _______ __________ _______ __________ _____________ _________ __________ _________________ ______________ _______ ________ ________ _______ _______ ________ ______ _______ _________ ________________ ________ ____________ ____________ __________ _____________ _________________
1996 1 18 4 2117 2120 2305 2259 {'HP'} 415 {'N637AW'} 108 99 85 6 -3 {'COS'} {'PHX'} 551 5 18 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 12 5 1252 1245 1511 1500 {'HP'} 610 {'N905AW'} 79 75 58 11 7 {'LAX'} {'PHX'} 370 3 18 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 16 2 1441 1445 1708 1721 {'HP'} 211 {'N165AW'} 87 96 74 -13 -4 {'RNO'} {'PHX'} 601 4 9 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 1 1 2258 2300 2336 2335 {'HP'} 1245 {'N183AW'} 38 35 20 1 -2 {'TUS'} {'PHX'} 110 6 12 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 4 4 1814 1814 1901 1910 {'US'} 683 {'N963VJ'} 47 56 34 -9 0 {'DTW'} {'PIT'} 201 6 7 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 31 3 1822 1820 1934 1925 {'US'} 757 {'N912VJ'} 72 65 52 9 2 {'PHL'} {'PIT'} 267 6 14 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 18 4 729 730 841 843 {'US'} 1564 {'N941VJ'} 72 73 58 -2 -1 {'DCA'} {'PVD'} 357 3 11 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 26 5 1704 1705 1829 1839 {'NW'} 1538 {'N960N' } 85 94 69 -10 -1 {'DTW'} {'RIC'} 456 3 13 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
Configure the values in the opts object to import opts.Sheet = '2007'; opts.SelectedVariableNames = [1:5]; opts.DataRange = '2:11'; M = readmatrix('airlinesmall_subset.xlsx',opts) M = 10×5
2007 1 2 2 711
2007 1 3 3 652
2007 1 4 4 1116
2007 1 5 5 825
2007 1 7 7 1411
2007 1 8 1 1935
2007 1 9 2 2005
2007 1 11 4 1525
2007 1 12 5 1133
2007 1 13 6 922
Read Matrix from Specified Sheet and RangePreview the data from a spreadsheet file and import numerical data, as a matrix, from a specified sheet and range. The spreadsheet file opts = detectImportOptions('airlinesmall_subset.xlsx'); preview('airlinesmall_subset.xlsx',opts) ans=8×29 table
Year Month DayofMonth DayOfWeek DepTime CRSDepTime ArrTime CRSArrTime UniqueCarrier FlightNum TailNum ActualElapsedTime CRSElapsedTime AirTime ArrDelay DepDelay Origin Dest Distance TaxiIn TaxiOut Cancelled CancellationCode Diverted CarrierDelay WeatherDelay SDelay SecurityDelay LateAircraftDelay
____ _____ __________ _________ _______ __________ _______ __________ _____________ _________ __________ _________________ ______________ _______ ________ ________ _______ _______ ________ ______ _______ _________ ________________ ________ ____________ ____________ __________ _____________ _________________
1996 1 18 4 2117 2120 2305 2259 {'HP'} 415 {'N637AW'} 108 99 85 6 -3 {'COS'} {'PHX'} 551 5 18 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 12 5 1252 1245 1511 1500 {'HP'} 610 {'N905AW'} 79 75 58 11 7 {'LAX'} {'PHX'} 370 3 18 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 16 2 1441 1445 1708 1721 {'HP'} 211 {'N165AW'} 87 96 74 -13 -4 {'RNO'} {'PHX'} 601 4 9 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 1 1 2258 2300 2336 2335 {'HP'} 1245 {'N183AW'} 38 35 20 1 -2 {'TUS'} {'PHX'} 110 6 12 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 4 4 1814 1814 1901 1910 {'US'} 683 {'N963VJ'} 47 56 34 -9 0 {'DTW'} {'PIT'} 201 6 7 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 31 3 1822 1820 1934 1925 {'US'} 757 {'N912VJ'} 72 65 52 9 2 {'PHL'} {'PIT'} 267 6 14 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 18 4 729 730 841 843 {'US'} 1564 {'N941VJ'} 72 73 58 -2 -1 {'DCA'} {'PVD'} 357 3 11 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
1996 1 26 5 1704 1705 1829 1839 {'NW'} 1538 {'N960N' } 85 94 69 -10 -1 {'DTW'} {'RIC'} 456 3 13 0 {0x0 char} 0 {0x0 char} {0x0 char} {0x0 char} {0x0 char} {0x0 char}
Import M = readmatrix('airlinesmall_subset.xlsx','Sheet','2007','Range','A2:E11') M = 10×5
2007 1 2 2 711
2007 1 3 3 652
2007 1 4 4 1116
2007 1 5 5 825
2007 1 7 7 1411
2007 1 8 1 1935
2007 1 9 2 2005
2007 1 11 4 1525
2007 1 12 5 1133
2007 1 13 6 922
Input Argumentscollapse all
filename — Name of file to read character vector | string scalarName of the file to read, specified as a character vector or a string scalar. Depending on the location of your file,
Data Types: opts — File import options SpreadsheetImportOptions | DelimitedtextImportOptions | FixedWidthImportOptions | XMLImportOptionsFile import options, specified as an Name-Value ArgumentsSpecify optional pairs of arguments as Before
R2021a, use commas to separate each name and value, and enclose Example: All Supported File Types collapse all WebOptions — HTTP or HTTPS request options weboptions object
Text and Spreadsheet Files collapse all FileType — Type of file 'text' | 'spreadsheet'Type of file, specified as the comma-separated pair consisting of Specify the
Example: Data Types: Number of header lines in the file, specified as the comma-separated pair consisting of Example: Data Types: ExpectedNumVariables — Expected number of variables positive integerExpected number of variables, specified as the comma-separated pair consisting of Data Types: Range — Portion of data to read character vector | string scalar | numeric vectorPortion of the data to read from text or spreadsheet files, specified as the comma separated pair consisting of
Data Types: TreatAsMissing — Text to interpret as missing data character vector | string scalar | cell array of character vectors | string arrayText to interpret as missing data, specified as a character vector, string scalar, cell array of character vectors, or string array. Example: Data Types: OutputType — Output data type character vector | string scalarOutput data type, specified as the comma-separated pair consisting of
Example: Data Types: Text Files Only collapse all Field delimiter characters in a delimited text file, specified as a character vector, string scalar, cell array of character vectors, or string array. Example: Example: Data Types: Characters to treat as white space, specified as a character vector or string scalar containing one or more characters. Example: Example: End-of-line characters, specified as a character vector, string scalar, cell array of character vectors, or string array. Example: Example: Example: Data Types: Style of comments, specified as a character vector, string scalar, cell array of character vectors, or string array. For example, to ignore the text following a percent sign on the same line, specify Example: Data Types:
Encoding — Character encoding scheme 'UTF-8' | 'ISO-8859-1' | 'windows-1251' | 'windows-1252' | ...Character encoding scheme associated with the file, specified as the comma-separated pair consisting of If you
specify the Example: Example: Data Types: DateLocale — Locale for reading dates character vector | string scalarLocale for reading dates, specified as the comma-separated pair consisting of
This table lists some common values for the locale.
When using the If you specify the Example:
Characters indicating the
decimal separator in numeric variables, specified as a character vector or string scalar. The importing function uses the characters specified in the When converting to integer data types, numbers with a decimal part are rounded to the nearest integer. Example: If name-value pair is specified as Data Types: Characters that indicate the thousands grouping in numeric variables, specified as a character vector or string scalar. The thousands grouping characters act as visual separators, grouping the number at every three place values. The importing function uses the characters specified in the Example: If name-value pair is specified
as Data Types: TrimNonNumeric — Remove nonnumeric characters false (default) | trueRemove nonnumeric characters
from a numeric variable, specified as a logical Example: If name-value pair is specified as Data Types: Procedure to handle consecutive delimiters in a delimited text file, specified as one of the values in this table.
Data Types: Procedure to manage leading delimiters in a delimited text file, specified as one of the values in this table.
TrailingDelimitersRule — Procedure to manage trailing delimiters 'keep' | 'ignore' | 'error'Procedure to manage trailing delimiters in a delimited text file, specified as one of the values in this table.
Spreadsheet Files Only collapse all Sheet to read from, specified as an empty character array, a character vector or string scalar containing the sheet name, or a positive scalar integer denoting the sheet index. Based on the value specified for the
Data Types: UseExcel — Flag to start instance of Microsoft Excel for Windows false (default) | trueFlag to start an instance of
Microsoft Excel for Windows when reading spreadsheet data, specified as the comma-separated pair consisting of You can set the
When reading from spreadsheet files on Windows platforms, if you want to start an instance of Microsoft Excel, then set the Version HistoryIntroduced in R2019a What is the process of displaying only a portion of the data based on matching a specific value to show only the data that meets the criteria that you specify is called?The process of displaying only a portion of the data based on matching a specific value to show only the data that meets the criteria that you specify is called: Filtering.
Is the process of arranging data in a specific order based on the values in the fields?Data sorting is any process that involves arranging the data into some meaningful order to make it easier to understand, analyze or visualize.
What provides a visual cue about the value of a cell relative to other cells?A cell format consisting of a shaded bar that provides a visual cue to the reader about the value of a cell relative to other cells; the length of the bar represents the value in the cell—a longer bar represents a higher value and a shorter bar represents a lower value.
What is the term for the values that a function used to perform operations or calculations?Arguments. The values that an Excel function uses to perform calculations or operations. AVERAGE Function. An Excel function that adds a group of values, and then divides the result by the number of values in the group.
|