Prev: continously data acquisition from Microphone
Next: is bootci with bootfun returning a vector possible? (at leastin newer versions of matlab)
From: arnold on 18 Jun 2010 07:54 I realized what is going wrong with the code. The code is used to read a text file that has 2 headerlines of information and then 3 columns of data. however, this data is hundreds of lines long and some ROWS of data are more than 3 columns long one segment of text data would look like this ex: 34, 456783, 0.23443 43, 567823, 0.55323 34, 323426, 0.52533 0, 0, 0.0000, 0, 0, 0 24, 234255, 0.53552 67, 534453, 0.23453 34, 435345, 0.23444 24, 243677, 0.24424 The program successfully reads the text data up to that row (or line) of data that has numbers in more than 3 columns, then the error occurs. Is there any way to pass like a functionhandle or something to tell the code to exclude that data i.e.: [A B C] = textread('file.txt', '%f %f %f', 'headerlines', 2, 'delimiter', ',', 'functionhandle'); the functionhandle being defined by a code that maybee sort of goes like this: if row has more than 3 numbers in it then exclude that row else keep the row end Please help thanks in advance, Arnold
From: us on 18 Jun 2010 12:08 arnold <fudgethebucket554(a)optonline.net> wrote in message <1429042517.368534.1276876472722.JavaMail.root(a)gallium.mathforum.org>... > I realized what is going wrong with the code. > The code is used to read a text file that has 2 headerlines of information and then 3 columns of data. > > however, this data is hundreds of lines long and some ROWS of data are more than 3 columns long > > one segment of text data would look like this ex: > > 34, 456783, 0.23443 > 43, 567823, 0.55323 > 34, 323426, 0.52533 > 0, 0, 0.0000, 0, 0, 0 > 24, 234255, 0.53552 > 67, 534453, 0.23453 > 34, 435345, 0.23444 > 24, 243677, 0.24424 > > The program successfully reads the text data up to that row (or line) of data that has numbers in more than 3 columns, then the error occurs. > > Is there any way to pass like a functionhandle or something to tell the code to exclude that data > > i.e.: > > [A B C] = textread('file.txt', '%f %f %f', > 'headerlines', 2, 'delimiter', ',', 'functionhandle'); > > the functionhandle being defined by a code that maybee sort of goes like this: > > if row has more than 3 numbers in it > then exclude that row > else keep the row > end > > Please help > thanks in advance, > Arnold one of the many solutions fnam='foo.txt'; % <- your file name... s=textread(fnam,'%s','delimiter','\n'); r=cellfun(@(x) sscanf(x,'%f,'),s,'uni',false); ix=cellfun(@numel,r)==3; r=r(ix); r=reshape(cat(2,r{:}).',[],3) %{ % r = 34 4.5678e+005 0.23443 43 5.6782e+005 0.55323 34 3.2343e+005 0.52533 24 2.3426e+005 0.53552 67 5.3445e+005 0.23453 34 4.3535e+005 0.23444 24 2.4368e+005 0.24424 %} us
From: arnold on 18 Jun 2010 09:14 thank you so much, the code seems ot work ok but some small bit of information that I left out might be messing up the data: The column 34, 43, 34, 0, 24, 67, 34, 24, are actually times, ex: 15:12:08 15:12:09 15:12:10 15:12:11, etc
From: us on 18 Jun 2010 13:36 arnold <fudgethebucket554(a)optonline.net> wrote in message <458876511.368863.1276881309429.JavaMail.root(a)gallium.mathforum.org>... > thank you so much, > the code seems ot work ok but some small bit of information that I left out might be messing up the data: > > The column 34, 43, 34, 0, 24, 67, 34, 24, are actually times, ex: > 15:12:08 > 15:12:09 > 15:12:10 > 15:12:11, etc well... that's just ...a bit... tedious... how could a solution look like(?)... us
From: arnold on 18 Jun 2010 09:52
so basically there is the numeric data that i showed and the first column is times. The data that I want to exclude (the zeros) is messed up data that I do not need. Everything else about the data is the same from my first post (or second rather) but there is just time data in the first column. |