How to properly import a text file -- importdata or dlmread?

2 views (last 30 days)
I'm a total amateur in MATLab, and only have limited experience with programming at all.
Here's what I've got: A bunch of files that have 19 rows of header text, no real column headers, and after that, three columns of data (X, Y1, and Y2). Eventually, I would like to put all files into a single matrix so I can plot and analyze them together. To start with though, I would just like to be able to get them into MATLab, minus the text, in the most logical fashion so that as I learn, I can start building a cohesive store of related data from these separate files.
I tried using import wizard, and I was able to create a variable that had all the right values in all the right places (basically looked like my original file, minus the header rows, in a sort of spreadsheet-looking variable). However, it kept generating a separate text variable (which contained the 19 header rows of text) that I don't need, and it wasn't giving me the option of generating 'vectors using column names', which I don't understand. Is import wizard (i.e. 'importdata') the way to go, or should I be using dlmread or some other function?
Any suggestions/help here would be much appreciated!

Answers (1)

Image Analyst
Image Analyst on 6 Feb 2013
How about this:
% skips the first 19 lines of the data, and then reads the remaining data,
% treating commas as a delimiter.
myMatrix = textscan(fileID,'%f','HeaderLines', 19,'Delimiter',',')
  1 Comment
Crystal
Crystal on 6 Feb 2013
I tried running that (but changed delimiter to '\t', as my data are tab delimited), and it returned a 1x1 cell. If I could just suppress the return of the text portion when I use "importdata", I wouldn't mind going that route. It just seems tedious and unnecessary to deal with it.
Any other suggestions?

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!