0

I'm a bit new to data import using Matlab. Basically, I have an Ascii file. It has 13 Header Lines, along with 765 columns and ~3500 rows of data. I am attempting to import the data into a 3500 x 765 matrix in Matlab. I've tried the following:

fileID = fopen('filename');
formatspec = [repmat('%f ', [1,765])];
raw_data=textscan(fileID,formatspec, 'Headerlines',13,'delimiter','\t');

It successfully skips the 13 header lines. However, it only gives me a 1 x 765 matrix containing only the data from the first row.

Perhaps I have misunderstood just how I am supposed to use textscan, so any help in getting my other ~3499 rows of data would be very well appreciated.

~Thank You

NOTE

The Data File itself is formatted as follows. The First 13 lines do not contain the data itself. All lines following that contain sets of data similar to what will be pasted below, extending for 700+ columns and 3000+ rows.

Wyko ASCII Data File Format 0 1 1

X Size 3571

Y Size 765

Block Name Type Length Value

Wavelength 7 4 72.482628

Aspect 7 4 1

Pixel_size 7 4 0.00196

StageY 7 4 -0.048055

Magnification 8 8 5.05

StageX 7 4 0.214484

ScannerPosition 7 4 3490.000732

ScannerSpeed 7 4 3.165393

RAW_DATA 3 10927260

-10976.61035 -10977.07324 -10981.07422 -10985.6084 ...

-10967.41309 -10963.31836 -10966.75195 -10980.40723 ...

-10969.08496 -10976.03711 -10976.62988 -10964.23731 ...

-10974.12695 -10976.61133 -10979.2627 -10973.57813 ...

-10969.21094 -10966.56543 -10973.74512 -10983.41797 ...

-10970.18359 -10980.82715 -10968.00195 -10975.58594 ...

-10980.41016 -10982.39356 -10982.74316 -10974.51563 ...

-10972.31641 -10984.00488 -10987.89453 -10976.23633 ...

Michael Hu
  • 83
  • 5

1 Answers1

0

I think the following should work, but I don't have Matlab on this machine to test it out.

 fileID = fopen('filename');
 formatspec = [repmat('%f ', [1,765])]; 
 raw_data = new_data = textscan(fileID,formatspec, 'Headerlines',13,'delimiter','\t');

 while ~feof(fileID)
    new_data = textscan(fileID,formatspec,'delimiter','\t');
    raw_data = [raw_data; new_data]; 
 end

 fclose(fileID);

Note that this is not a particularly efficient way to do it. If your header lines give you the size of your array, you may want to use zeros to create an array of the appropriate size and then read the data into your array.

S. Miller
  • 379
  • 3
  • 15