Importing data from an ascii file.

8 views (last 30 days)
Matthew
Matthew on 3 Apr 2014
Commented: Joseph Cheng on 3 Apr 2014
I want to import data into a matrix in matlab. The issue arises because I have a bunch of junk that I don't want before my data. How can I import my data into matlab output it in a matrix in a certain file name. My data looks like this
JUNK JUNK JUNK JUNK JUNK JUNK JUNK JUNK JUNK JUNK JUNK
#' Start of Data:
Data I want
The "# Start of Data:" is actually there I want everything after that line. Any assistance you can give would be very appreciated.

Answers (2)

Joseph Cheng
Joseph Cheng on 3 Apr 2014
you can use dlmread() which you can specify the specific row and column to start importing the data. One thing to remember dlmread starts counting with 0 not 1 like the rest of matlab. so the first column and row is both 0.
  2 Comments
Matthew
Matthew on 3 Apr 2014
So if my data was on the 200th line and was separated with spaces I'd use
dlmread('filename.asc', ' ', 200, 0)
Is that correct? I don't have that much experience with coding.
Joseph Cheng
Joseph Cheng on 3 Apr 2014
I'd test it out? but i think it may be 199 line but easiest way to check is to either try it or open the txt file in a text editor that displays line numbers and see whether the junk is from 0 to 199 or 1 to 200. Both would have 200 lines but dlmread counts the first row as 0.

Sign in to comment.


Image Analyst
Image Analyst on 3 Apr 2014
Use the new readtable function:
t = readtable(fullFileName, 'HeaderLines', 1); % Skip 1 line in the file.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!