How can I skip the first 3 lines and read two columns of numerical data as a matrix?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (1)
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
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.
See Also
Categories
Find more on Logical 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!