Skip to main content

9.2) Import Data


  • The Matlab function importdata is a generic loader of data
  • From the file name extension, it will attempt to load the data accordingly
  • It can load image files, spreadsheets and text files
  • It can import data that has been copied to the clipboard (in Windows <Ctrl>-<c> or on Mac <cmd>-<c>)
  • It can handle headers and different types of delimitation (comma delimited, white space, etc) in text files. The syntax of importdata is as follows:

[matlab]
>> % load data from filename into array A
>> A=importdata(filename)
>> % import data from copy
>> A=importdata('-pastespecial')
>> % adding delimiter string to specify delimiter
>> A=importdata(..., delimiter)
>> % adding headerlines scalar tells importdata to start importing data at headerlines+1
>> A=importdata(..., delimiter,headerlines)
>>
[/matlab]
Examples of its use:
[matlab]
>> A=importdata('ngc6543a.jpg');
>> image(A);
>>
>> filename='myfile01.txt'; delimiter=''; headerlines=1;
>> A=importdata(filename, delimiter, headerlines)
[/matlab]