Re: Mathematica - convert engineering form to numeric data
- From: Jean-Marc Gulliet <jeanmarc.gulliet@xxxxxxxxx>
- Date: Sat, 29 Sep 2007 18:27:01 +0200
Dave wrote:
Szabolcs Horvát wrote:Dave wrote:That certainly reads the file properly (unlike my previous attempt), but I'm not sure how to now filter the line with the time stamp (07:35:39) that I want. There are thousands of lines, but I want to extract only the one with the text "07:35:39", so that I can plot its contents.
Unlike 'FindList', 'Import' does not have any method of filtering the lines read.
Use Cases or Select after you've read the data. Or use ImportString on the output of FindList. Or use an external utility, such as grep, to filter the file before you read it (probably the fastest method):
Import["!grep \"07:35:39\" datafile", "Table"]
Thank you.
I could use grep, and in fact I originally way, but I'd like to do it in Mathematica, as it makes it platform independant.
Someone suggested the following by email, where he used Cases and tested on a file with 5 columns. Unfortunately, my data file as over 100 columns, so the Cases[] command becomes huge if I try to use it.
*****************************
I slapped together a little test file values.dat
07:35:39 -1.185637512E+002 123.E-1 1.24375 5
08:35:39 -2.185637512E+002 124.E-1 1.24365 4
07:34:39 -3.185637512E+002 125.E-1 1.24355 3
07:35:59 -1.185637512E+002 126.E-1 1.24345 2
07:35:32 -5.185637512E+002 127.E-1 1.24335 1
06:35:39 -1.185637512E+002 128.E-1 1.24325 0
07:34:39 -1.185637512E+002 129.E-1 1.24315 9
and then used this to select your desired line from it
Cases[Import["values.dat", "Table"], {"07:35:39", _, _, _, _}]
and it returns
{{07:35:39, -118.564, 12.3, 1.24375, 5}}
****************************
Hence the following does work (and in fact I am now using it). But it was a bit tedious to do with 104 columns, and would be a nightmare with thousands.
PlotAtTimeStamp[filename_, time_]:=
Block[ {},
data = Import[file, "Table"];
First[Cases[
data, {time, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, \
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, \
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, \
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, \
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, \
_, _, _}]];
]
Any suggests how I can make the Cases[] more like grep, so it only searches for the string, and does not have to match every single column?
In[1]:= Cases[Import["values.dat", "Table"], {"07:35:39", __}]
Out[1]= {{"07:35:39", -118.564, 12.3, 1.24375, 5}}
Any expression: _ (one dash)
One or more: __ (two dashes)
Zero, one, or more: ___ (three dashes)
http://reference.wolfram.com/mathematica/guide/Patterns.html
Regards,
--
Jean-Marc
.
- Follow-Ups:
- Re: Mathematica - convert engineering form to numeric data
- From: Dave (from the UK)
- Re: Mathematica - convert engineering form to numeric data
- References:
- Mathematica - convert engineering form to numeric data
- From: Dave
- Re: Mathematica - convert engineering form to numeric data
- From: Richard J. Fateman
- Re: Mathematica - convert engineering form to numeric data
- From: Dave (from the UK)
- Re: Mathematica - convert engineering form to numeric data
- From: Daniel Lichtblau
- Re: Mathematica - convert engineering form to numeric data
- From: Dave
- Re: Mathematica - convert engineering form to numeric data
- From: Szabolcs Horvát
- Re: Mathematica - convert engineering form to numeric data
- From: Dave
- Mathematica - convert engineering form to numeric data
- Prev by Date: Re: Mathematica - convert engineering form to numeric data
- Next by Date: Re: Mathematica - convert engineering form to numeric data
- Previous by thread: Re: Mathematica - convert engineering form to numeric data
- Next by thread: Re: Mathematica - convert engineering form to numeric data
- Index(es):
Relevant Pages
|
|