MATLAB: Reading data row by row into matlab.

data importtext file

I need to read a text file, row by row, into different variables for the first 5 rows. Afterwards an N x M matrix needs to be read in. Is there a simple way to do this? I've tried to use textrfead, fopen, etc, but can't figure out how to get just the numbers I need.
this would be a sample file:
8
10
12 15 12 18 17 19 14 16
200 155 487 632 526 321 845 80
52 41 78 62 32 45 67 85 29 10 15
followed by a matrix of size 8 x10 (the matrix will always be size of the first two inputs)
Sorry, I uploaded two sample files. I know how to read in everything but the matrix at the end. That's what I need help retrieving from the files.

Best Answer

Why not just use dlmread ?:
>> M = dlmread('test.txt','',2,0)
M =
12 15 12 18 17 19 14 16 0 0 0
200 155 487 632 526 321 845 80 0 0 0
52 41 78 62 32 45 67 85 29 10 15
I had to create my own test file (attached) based on your description because you did not provide one. If you upload a sample file then it makes it easier for us to help you, and faster for you to get the results that you want.
Related Question