| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
importdata(filename)
A = importdata(filename)
A = importdata(filename, delimiter)
A = importdata(filename, delimiter, nheaderlines)
[A, delimiter]
= importdata(...)
[A, delimiter, nheaderlines]
= importdata(...)
[...] = importdata('-pastespecial', ...)
importdata(filename) loads data from filename into the workspace.
A = importdata(filename) loads data into A.
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.
filename |
Name and extension of the file to import. If importdata recognizes the file extension, it calls the MATLAB helper function designed to import the associated file format (such as load for MAT-files or xlsread for spreadsheets). Otherwise, importdata interprets the file as a delimited ASCII file. For a list of supported file formats, see the file formats table. |
delimiter |
Character in an ASCII file to interpret as a column separator, such as ',' or ';'. Use '\t' for tab. Default: interpreted from file |
nheaderlines |
Number of text header lines in the input ASCII file. importdata stores all the header text in the textdata field, and stores the last line of column header text in the colheaders field. Default: interpreted from file |
'-pastespecial' |
Keyword to request that importdata load data from the system clipboard instead of a file. |
A |
Data from the file. The class of A depends on the characteristics of the input file. As described in the Inputs section, importdata calls a helper function to read the data. When the helper function returns more than one nonempty output, importdata combines the outputs into a struct array. The following table lists the file formats associated with helper functions that can return more than one output, and the possible fields in A.
The MATLAB helper functions for all other supported file formats return one output. For more information about the class of each output, see the functions listed in the file formats table. For ASCII files and spreadsheets, importdata expects to find numeric data in a rectangular form (that is, like a matrix). Text headers can appear above or to the left of the numeric data, as follows:
To import ASCII files with nonnumeric characters anywhere else, including columns of character data or formatted dates or times, use textscan instead of importdata. For more information, see Importing Nonnumeric ASCII Data. When importing spreadsheets with columns of nonnumeric data, importdata cannot always correctly interpret the column and row headers. If the ASCII file or spreadsheet contains either column or row headers, but not both, importdata returns a colheaders or rowheaders field in the output structure, where:
| |||||||||||||||
delimiter |
The character that importdata detected as the column separator in the input ASCII file. | |||||||||||||||
nheaderlines |
The number of text header lines that importdata detected in the input ASCII file. |
Import and display the image ngc6543a.jpg:
nebula_im = importdata('ngc6543a.jpg');
image(nebula_im);nebula_im is class uint8 because the helper function, imread, returns empty results for colormap and alpha.
Using a text editor, create a space-delimited ASCII file with column headers called myfile.txt:
Day1 Day2 Day3 Day4 Day5 Day6 Day7 95.01 76.21 61.54 40.57 5.79 20.28 1.53 23.11 45.65 79.19 93.55 35.29 19.87 74.68 60.68 1.85 92.18 91.69 81.32 60.38 44.51 48.60 82.14 73.82 41.03 0.99 27.22 93.18 89.13 44.47 17.63 89.36 13.89 19.88 46.60
Import the file, specifying the space delimiter and the single column header, and view columns 3 and 5:
M = importdata('myfile.txt', ' ', 1);
for k = [3, 5]
disp(M.colheaders{1, k})
disp(M.data(:, k))
disp(' ')
end
The easiest way to import data is to use the Import Wizard, a graphical user interface. The Import Wizard imports the same file formats as importdata, but allows direct control over the variables to create. To start the Wizard, select File > Import Data or call uiimport.
file formats | load | save | textscan | uiimport
![]() | import | imread | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |