From: Baalzamon on 12 Apr 2010 10:36 Hi I have a tricksome problem (for me anyway) I am using fgetl to read lines from a text file. However I only want the number parts of it. Is there a way to just extract the numbers before the ascii chars at then end and then use str2num to make a matrix? .0124 200 900 260 600 .2140 .1586 .3179 80.0000 10.0000 10.0000 .0000 -.0180 .0213 301.0000 .1000 .4100 .3700 .4100 .3700 4.6000 9.4000 100.0000 1.202 .077 405.00 337 99.36 .1176 .0000 100.0000 .0000 ‚¼kà|@@ .5562 296.1225 .0000**********ÙHjtµQA This is an example of the line from my file. I don't want the bits from the comma (by the quarter symbol). However each line is different so the chars won't be the same.
From: dpb on 12 Apr 2010 10:50 Baalzamon wrote: > Hi I have a tricksome problem (for me anyway) > I am using fgetl to read lines from a text file. However I only want the > number parts of it. Is there a way to just extract the numbers before > the ascii chars at then end and then use str2num to make a matrix? > .0124 200 900 260 600 .2140 .1586 .3179 80.0000 > 10.0000 10.0000 .0000 -.0180 .0213 301.0000 .1000 > .4100 .3700 .4100 .3700 4.6000 9.4000 100.0000 1.202 > .077 405.00 337 99.36 .1176 .0000 100.0000 .0000 > ‚¼kà|@@ .5562 296.1225 .0000**********ÙHjtµQA > > This is an example of the line from my file. I don't want the bits from > the comma (by the quarter symbol). However each line is different so the > chars won't be the same. The font you used doesn't render well so not sure where there is a comma but if there are a fixed number of fields (that is each record is a fixed number of records and the numeric fields are in the same positions you should be able to use textscan() or textread() and a formatting string otoo fmt=[repmat('%f ',1,N) '%*s' repmat('%f ',1,M) '%*s']; where N is the number of numeric fields before the first string to ignore and M the second set of numeric fields and another %*s to finish off the record. --
From: Baalzamon on 12 Apr 2010 14:17 Ah cheers. However the number of fields can vary as sometimes the fields get merged together...If I add some form of loop (test statement loop etc) should this get around it?
From: dpb on 12 Apr 2010 14:36 Baalzamon wrote: > Ah cheers. However the number of fields can vary as sometimes the fields > get merged together...If I add some form of loop (test statement loop > etc) should this get around it? What does "fields get merged together" mean? If it's a fixed-width field that doesn't always have room for a blank then simply create the proper width format field for each. If there are actually a variable number of fields/record then you'll have to parse each line individually and determine what is/isn't a valid number to convert. I'll not delve into that until confirm that's the actual problem. --
From: Branko on 12 Apr 2010 17:19
"Baalzamon " <baalzamon_moridin(a)yahoo.com> wrote in message <hpvb4k$hep$1(a)fred.mathworks.com>... > Hi I have a tricksome problem (for me anyway) > I am using fgetl to read lines from a text file. However I only want the number parts of it. Is there a way to just extract the numbers before the ascii chars at then end and then use str2num to make a matrix? > .0124 200 900 260 600 .2140 .1586 .3179 80.0000 10.0000 10.0000 .0000 -.0180 .0213 301.0000 .1000 .4100 .3700 .4100 .3700 4.6000 9.4000 100.0000 1.202 .077 405.00 337 99.36 .1176 .0000 100.0000 .0000 ‚¼kà|@@ .5562 296.1225 .0000**********ÙHjtµQA > > This is an example of the line from my file. I don't want the bits from the comma (by the quarter symbol). However each line is different so the chars won't be the same. doc regexp Branko |