text import - number of rows
2 views (last 30 days)
Show older comments
Hi, I have the following code to read in a bunch of data from a textfile as shown below. In this example, the number of rows is 5. But, I don't always know the number of rows, so I want the code to read all the rows and calculate how many automatically. Anyone know how to?
n=5;
filename1='import.asc'
fid = fopen(filename1);
Q{i,1}=textscan(fid,'%u %f %f %f %f %f %f',n,'headerlines',rad(i)+4);
fclose(fid);
//////////////////////////////////////////////////////////////////////////////////////////
127 -0.29784E-03 0.64028E-06-0.23385E-02 0.24409E-06 0.13348E-06-0.69277E-03
128 -0.33237E-03-0.43242E-06-0.33875E-02 0.82221E-06 0.24963E-06-0.14770E-02
129 -0.40024E-03-0.28975E-06-0.52177E-02 0.40892E-06 0.23521E-06-0.23949E-02
130 -0.49607E-03-0.50922E-06-0.79652E-02 0.69354E-06 0.49298E-06-0.35142E-02
131 -0.61997E-03-0.63708E-06-0.11812E-01 0.92476E-06 0.94470E-06-0.49007E-02
///////////////////////////////////////////////////////////////////////////////////////////
2 Comments
Stephen23
on 1 Feb 2016
Can you please upload a sample file. Click the paperclip button, then both Choose file and Attach file buttons.
Is this block the only text in the file? Are there multiple blocks? Do the blocks repeat? Are their header lines above each block?
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Text Data Preparation 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!