How can I skip the first 3 lines and read two columns of numerical data as a matrix?

3 views (last 30 days)
Dear friends, Enclosed please find a text file. I want to skip the first 3 lines and read the remaining numerical data in 2 columns as a matrix. Many thanks in advance

Accepted Answer

Star Strider
Star Strider on 14 Mar 2015
Use textscan:
fidi = fopen('rp_test.txt', 'rt');
d = textscan(fidi, '%f %f', 'HeaderLines',2);
figure(1)
plot(d{1}, d{2})
xlabel('"Flow Time"')
ylabel('"Area-Weighted Average Pressure Coefficient"')
grid
  13 Comments
h
h on 16 Mar 2015
YES, FINALLY it works... You are right... I just needed to put that (\). I have been so excited once I saw the figures... Many thanks for your persistent help... you did a GREAT job for me, and saved my time a lot, as I am using a program which produces those input files after each run...

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Mar 2015
You didn't attach anything but I'd recommend trying dlmread(). It has an input option where you can tell it to skip past some specified number of header lines.
  3 Comments
Image Analyst
Image Analyst on 14 Mar 2015
Edited: Image Analyst on 14 Mar 2015
You could have looked up dlmread() or importdata(), but it looks like Star gave you a solution that also works.
A = importdata(fullFileName, delimiterIn, headerlinesIn);
To read many files, see the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F If our suggestions help, then you can "Vote" for our suggestions.

Sign in to comment.

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!