Prev: uicontrol edit
Next: 3 equations 2 unknows
From: D on 29 May 2010 19:55 Hello, I am having difficulty figuring out in Matlab how to import two sets of data located within a single .txt file: - Each data set has its own row x col dimensions and headers - The second data set is seen a few tabs beneath the last row of the first data set - txt file is tab delimited. So, for example, a .txt file looks something like this: data set #1: row(1): header(1) header(2) header(3) ... header(m+10) .. data(1) . . . .. . . . . row(n): data(n) . . . data set #2: row(n+5): header(1) header(2) header(3) ... header(m+6) .. data(n+6) . . . .. . . . . row(...): data(...) . . . Since I have many txt files to import, I would like to import directly into Matlab, and would like to avoid txt > excel > matlab. I have tried importdata, and it works great up to row(n+5), but I can't it get it start at row(n+5) to end. Thank you for reading, and I appreciate any advice and direction. - Dale
From: TideMan on 29 May 2010 22:28 On May 30, 11:55 am, "D " <dale....(a)gatech.edu> wrote: > Hello, > > I am having difficulty figuring out in Matlab how to import two sets of data located within a single .txt file: > - Each data set has its own row x col dimensions and headers > - The second data set is seen a few tabs beneath the last row of the first data set > - txt file is tab delimited. > > So, for example, a .txt file looks something like this: > data set #1: > row(1): header(1) header(2) header(3) ... header(m+10) > . data(1) . . . > . . . . . > row(n): data(n) . . . > > data set #2: > row(n+5): header(1) header(2) header(3) ... header(m+6) > . data(n+6) . . . > . . . . . > row(...): data(...) . . . > > Since I have many txt files to import, I would like to import directly into Matlab, and would like to avoid txt > excel > matlab. I have tried importdata, and it works great up to row(n+5), but I can't it get it start at row(n+5) to end. > > Thank you for reading, and I appreciate any advice and direction. > > - Dale Assuming n is not too large (a few thousand, say), the way I'd do it is to read the entire file into Matlab using fscanf: a=fscanf(fid,'%c'); a is now a long string with LF i.e. char(10) marking the end of each line. You can use the Matlab string finding functions to locate the end of the first block and the start of the next, then you can use sscanf to transfer the data into matrices.
|
Pages: 1 Prev: uicontrol edit Next: 3 equations 2 unknows |