3 added 752 characters in body
source | link

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.txt. >>
Out[257]= $Failed
 

In earlier versionsSample Data Set (tabs get replaced by 4xwhitespace)

Here the position of Mathematicainterest would be e.g. "2. dataset". From there one I'd like to read the tab delimited columns couldsampling frequency and the number of sample points, which then can be accessed with:used to read in the {time, value} paired data.

samplingFreq = readNumber[{"Sampling frequency", 3}]

1. dataset

Number of points        3
Sampling frequency  [Hz]    12000


Time [s]    Value
--------    -----

0.000000    0.8972
0.003333    0.9015
0.006667    0.9061

2. dataset

Number of points        4
Sampling frequency  [Hz]    12000


Time [s]    Value
--------    -----

0.000000    0.8972
0.003333    0.518
0.006667    0.8971
0.006667    0.8648

3. dataset

Number of points        3
Sampling frequency  [Hz]    12000


Time [s]    Value
--------    -----

0.000000    0.7716
0.003333    0.2674
0.006667    0.8899

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.txt. >>
Out[257]= $Failed

In earlier versions of Mathematica the tab delimited columns could be accessed with:

samplingFreq = readNumber[{"Sampling frequency", 3}]

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.txt. >>
Out[257]= $Failed
 

Sample Data Set (tabs get replaced by 4xwhitespace)

Here the position of interest would be e.g. "2. dataset". From there one I'd like to read the sampling frequency and the number of sample points, which then can be used to read in the {time, value} paired data.

1. dataset

Number of points        3
Sampling frequency  [Hz]    12000


Time [s]    Value
--------    -----

0.000000    0.8972
0.003333    0.9015
0.006667    0.9061

2. dataset

Number of points        4
Sampling frequency  [Hz]    12000


Time [s]    Value
--------    -----

0.000000    0.8972
0.003333    0.518
0.006667    0.8971
0.006667    0.8648

3. dataset

Number of points        3
Sampling frequency  [Hz]    12000


Time [s]    Value
--------    -----

0.000000    0.7716
0.003333    0.2674
0.006667    0.8899
2 typo
source | link

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.contxt. >>
Out[257]= $Failed

In earlier versions of Mathematica the tab delimited columns could be accessed with:

samplingFreq = readNumber[{"Sampling frequency", 3}]

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.con. >>
Out[257]= $Failed

In earlier versions of Mathematica the tab delimited columns could be accessed with:

samplingFreq = readNumber[{"Sampling frequency", 3}]

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.txt. >>
Out[257]= $Failed

In earlier versions of Mathematica the tab delimited columns could be accessed with:

samplingFreq = readNumber[{"Sampling frequency", 3}]

1
source | link

Parsing tab delimited file

Problem Description

I have my data arranged in a tab delimited file and I'm trying to parse/access certain parts of it.

As an example, I'd like to extract the number of points and the sampling frequency as well as the time series which is saved like below (>> = tab, bullet = space):

Data file

Before and after this excerpt, there is a lot of other data that I don't need.

Attempt

I tried to find the position of interest in the file with the Find command and then readin the values with Read. I must be doing something wrong as an invalid data format error is thrown.

stream = OpenRead["test.txt"];
(* Find the line, that begins with "Number of points" *)
remarks = Find[stream,"Number of points"] (* now pointer at end of line *)

(* The next line is: Sampling frequency [Hz]    12000*)
Read[stream, {String, String, Real}, RecordSeparators->{"\t"}]

Output:

Out[256]= Number of points      100000
During evaluation of In[255]:= Read::readn: Invalid real number found when reading from test.con. >>
Out[257]= $Failed

In earlier versions of Mathematica the tab delimited columns could be accessed with:

samplingFreq = readNumber[{"Sampling frequency", 3}]