Matlab learning: importdat function details, Matlab importdat
Importdata
Load data from file
Syntax
Importdata (filename)
A = importdata (filename)
A = importdata (filename, delimiter)
A = importdata (filename, delimiter, nheaderlines)
[A, delimiter] = importdata (...)
[A, delimiter, nheaderlines] = importdata (...)
[...] = Importdata ('-pastespecial ',...)
Description
Importdata (filename) loads data from filename into the workspace.
A = importdata (filename) loads data into.
A = importdata (filename, delimiter) interprets delimiter as the column separator in ASCII file filename.
A = importdata (filename, delimiter, nheaderlines) loads data from ASCII file filename, reading numeric data starting from line nheaderlines + 1.
[A, delimiter] = importdata (...) returns the detected delimiter character for the input ASCII file.
[A, delimiter, nheaderlines] = importdata (...) returns the detected number of header lines in the input ASCII file.
[...] = Importdata ('-pastespecial',...) loads data from the system clipboard rather than from a file.
Note:
The main feature of the importdata function is that the data imported from a text file can be in the form of a table. It can contain the header, that is, the column name, or the header. The header can be in the text format. In addition to the official documentation, I found that the data imported by importdata can contain row names in addition to column names. During import, the column names are placed in the colheaders array, and the row names are placed in the rowheaders array. Importdata can also be used to import images, input the image name can be linked to a very detailed https://www.yiibai.com/matlab/matlab_data_import.html
The content of data.txt is as follows:
A1 a2 a3
B1 b2 b3
1 2 3
4 4 4
6 5 6
Test code:
DelimiterIn = ''; % character separator headerlinesIn = 2; % number of lines in the file header A = importdata('data.txt ', delimiterIn, headerlinesIn); Adata = A. datatextdata = A. textdatacolheaders =.
Running result:
A = data: [3x3 double] textdata: {2x3 cell} colheaders: {'b1' 'b2' 'b3'}data = 1 2 3 4 4 4 6 5 6textdata = 'a1 a2 a3' [] [] 'b1' 'b2' 'b3'colheaders = 'b1' 'b2' 'b3'
Note:
TextdataReadHeaderlinesInIdentified n-line header files,ColheadersYesHeaderlinesInThe last row is used as the column name.TextdataExceptHeaderlinesInBesides,The other lines are read as a string without being separated.
2016.07.19 update:
If there is no file header, importdata reads an array instead of A data Structure and cannot access data using A. data. You can simply use.