Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
extract dynamically the headerlines row numvber by string/number txt

Subject: extract dynamically the headerlines row numvber by string/number txt

From: Engeltje

Date: 29 Jun, 2008 18:27:56

Message: 1 of 13

hi, everybody...I had a problem.
I work with some namefile.tsv (a kind of txt files) that arecomposed
by some headerlines, containg string values and number values in Date
format and in the end of the file it contains some numerical colomns.
I want
either the row number of the begin of these numerical data, descarting
the headerlines, end the row number of the end of the file
or just the numbers contained in the end of the file disposed as a
table.

How can I obtain that dynamically? tha is create a function that do
this work for different file with different numbers of headerlines?

please help me!!!

thx, angelo!

Subject: extract dynamically the headerlines row numvber by string/number

From: Rune Allnor

Date: 29 Jun, 2008 19:15:49

Message: 2 of 13

On 29 Jun, 20:27, Engeltje <Engeltj...@gmail.com> wrote:
> hi, everybody...I had a problem.
> I work with some namefile.tsv (a kind of txt files) that arecomposed
> by some headerlines, containg string values and number values in Date
> format and in the end of the file it contains some numerical colomns.
> I want
> either the row number of the begin of these numerical data, descarting
> the headerlines, end the row number of the end of the file
> or just the numbers contained in the end of the file disposed as a
> table.
>
> How can I obtain that dynamically? tha is create a function that do
> this work for different file with different numbers of headerlines?

If you know the format of the table you are looking for,
you can use a regular expression to search for it, and
discard the lines that don't match the pattern.

Rune

Subject: extract dynamically the headerlines row numvber by string/number

From: Engeltje

Date: 30 Jun, 2008 08:44:09

Message: 3 of 13

On 29 Giu, 21:15, Rune Allnor <all...@tele.ntnu.no> wrote:
> On 29 Jun, 20:27, Engeltje <Engeltj...@gmail.com> wrote:
>
> > hi, everybody...I had a problem.
> > I work with some namefile.tsv (a kind of txt files) that arecomposed
> > by some headerlines, containg string values and number values in Date
> > format and in the end of the file it contains some numerical colomns.
> > I want
> > either the row number of the begin of these numerical data, descarting
> > the headerlines, end the row number of the end of the file
> > or just the numbers contained in the end of the file disposed as a
> > table.
>
> > How can I obtain that dynamically? tha is create a function that do
> > this work for different file with different numbers of headerlines?
>
> If you know the format of the table you are looking for,
> you can use a regular expression to search for it, and
> discard the lines that don't match the pattern.
>
> Rune

Actually, if you mean with "format", what kind of type the colomns
are, they're integer and float!
But if you mean if they're of the same colomns number, the answer is
no! these files are different!!
But we have in the bottom of these files some colomns of number, and I
don't know if matlab can see those as a table.
I'm very confused!
and If I can search for it, How can I do that discarding the
headerlines?
For instance in the first colomn the discarding lines are string
values, while the interesting ones are integer value!
Can u let me see an example? if u can...
thx to answer!
angelo

Subject: extract dynamically the headerlines row numvber by string/number txt

From: Miroslav Balda

Date: 30 Jun, 2008 08:55:03

Message: 4 of 13

Engeltje <Engeltje81@gmail.com> wrote in message
<2924bec5-2274-4b3b-8354-20b34f59add2@m3g2000hsc.googlegroups.com>...
> hi, everybody...I had a problem.
> I work with some namefile.tsv (a kind of txt files) that
arecomposed
> by some headerlines, containg string values and number
values in Date
> format and in the end of the file it contains some
numerical colomns.
> I want
> either the row number of the begin of these numerical
data, descarting
> the headerlines, end the row number of the end of the file
> or just the numbers contained in the end of the file
disposed as a
> table.
>
> How can I obtain that dynamically? tha is create a
function that do
> this work for different file with different numbers of
headerlines?
>
> please help me!!!
>
> thx, angelo!

Hi Angelo,

If the form of a file is not known in forward, you may use
the function ffread (free format read) from FEX (Id 9034),
which was developed just for the purpose.

Good luck.

Mira

Subject: extract dynamically the headerlines row numvber by string/number

From: Rune Allnor

Date: 30 Jun, 2008 09:01:13

Message: 5 of 13

On 30 Jun, 10:44, Engeltje <Engeltj...@gmail.com> wrote:
> On 29 Giu, 21:15, Rune Allnor <all...@tele.ntnu.no> wrote:
>
>
>
>
>
> > On 29 Jun, 20:27, Engeltje <Engeltj...@gmail.com> wrote:
>
> > > hi, everybody...I had a problem.
> > > I work with some namefile.tsv (a kind of txt files) that arecomposed
> > > by some headerlines, containg string values and number values in Date
> > > format and in the end of the file it contains some numerical colomns.
> > > I want
> > > either the row number of the begin of these numerical data, descarting
> > > the headerlines, end the row number of the end of the file
> > > or just the numbers contained in the end of the file disposed as a
> > > table.
>
> > > How can I obtain that dynamically? tha is create a function that do
> > > this work for different file with different numbers of headerlines?
>
> > If you know the format of the table you are looking for,
> > you can use a regular expression to search for it, and
> > discard the lines that don't match the pattern.
>
> > Rune
>
> Actually, if you mean with "format", what kind of type the colomns
> are, they're integer and float!
> But if you mean if they're of the same colomns number, the answer is
> no! these files are different!!

If you don't know what you are looking for and where to
find it, you are in serious trouble.

> But we have in the bottom of these files some colomns of number, and I
> don't know if matlab can see those as a table.

Matlab can't. You need to specify some properties that
separate those lines from the uninteresting stuff.
If you can do that, you can search for those prpoerties
using regular expressions.

> I'm very confused!
> and If I can search for it, How can I do that discarding the
> headerlines?

Use regular expressions.

> For instance in the first colomn the discarding lines are string
> values, while the interesting ones are integer value!

Use regular expressions.

Rune

Subject: extract dynamically the headerlines row numvber by string/number txt

From: Miroslav Balda

Date: 30 Jun, 2008 16:33:02

Message: 6 of 13

Engeltje <Engeltje81@gmail.com> wrote in message
<2924bec5-2274-4b3b-8354-20b34f59add2@m3g2000hsc.googlegroups.com>...
> hi, everybody...I had a problem.
> I work with some namefile.tsv (a kind of txt files) that
arecomposed
> by some headerlines, containg string values and number
values in Date
> format and in the end of the file it contains some
numerical colomns.
> I want
> either the row number of the begin of these numerical
data, descarting
> the headerlines, end the row number of the end of the file
> or just the numbers contained in the end of the file
disposed as a
> table.
>
> How can I obtain that dynamically? tha is create a
function that do
> this work for different file with different numbers of
headerlines?
>
> please help me!!!
>
> thx, angelo!

Hi,

Could you send a small example file with some notes what
data you like to read.? I'll try to read it

Mira

Subject: extract dynamically the headerlines row numvber by string/number

From: Engeltje

Date: 1 Jul, 2008 08:40:15

Message: 7 of 13

On 30 Giu, 18:33, "Miroslav Balda" <balda.nos...@cdm.it.cas.cz> wrote:
> Engeltje <Engeltj...@gmail.com> wrote in message
>
> <2924bec5-2274-4b3b-8354-20b34f59a...@m3g2000hsc.googlegroups.com>...
>
> > hi, everybody...I had a problem.
> > I work with some namefile.tsv (a kind of txt files) that
> arecomposed
> > by some headerlines, containg string values and number
> values in Date
> > format and in the end of the file it contains some
> numerical colomns.
> > I want
> > either the row number of the begin of these numerical
> data, descarting
> > the headerlines, end the row number of the end of the file
> > or just the numbers contained in the end of the file
> disposed as a
> > table.
>
> > How can I obtain that dynamically? tha is create a
> function that do
> > this work for different file with different numbers of
> headerlines?
>
> > please help me!!!
>
> > thx, angelo!
>
> Hi,
>
> Could you send a small example file with some notes what
> data you like to read.? I'll try to read it
>
> Mira

Hi Mira!!!
The problem I had I found a solution using the function
txt2mat(filename,0,1) I take the first colomn and then I made a
function that check if the result vector isnan (in this case increase
first index) else increase second index.
so thx to be interested!
Now I actually have a new problem!
I have some data in which part of the colomn is emtpy.
Example:

timestamp X Y value
10
20 3.2 3.4 4
30
40 1.2 2.7 10

I use:
values=textscan(filename,'%d %f %f %d', 4,'headerlines',1);

[TS,GazePointX,GazePointY,val]=values{:}

the problem is that it stops at TS=10, and the others are empty
Can u help me?
angelo

Subject: extract dynamically the headerlines row numvber by string/number

From: Miroslav Balda

Date: 1 Jul, 2008 09:35:08

Message: 8 of 13

Engeltje <Engeltje81@gmail.com> wrote in message
<155421db-2dae-4c05-a69a-7bd91a8f6793@r66g2000hsg.googlegroups.com>...
:
SNIP
:
> Now I actually have a new problem!
> I have some data in which part of the colomn is emtpy.
> Example:
>
> timestamp X Y value
> 10
> 20 3.2 3.4 4
> 30
> 40 1.2 2.7 10
>
> I use:
> values=textscan(filename,'%d %f %f %d', 4,'headerlines',1);
>
> [TS,GazePointX,GazePointY,val]=values{:}
>
> the problem is that it stops at TS=10, and the others are
empty
> Can u help me?
> angelo

Hi Angelo,

I think that you have to use another approach to it, and
read the file line by line. Look at
help fgetl and
help fgets.
after getting a line contents you may analyze it by function
sscanf
and decide what to do with half-empty line.

Mira

Subject: extract dynamically the headerlines row numvber by string/number

From: Engeltje

Date: 1 Jul, 2008 10:43:41

Message: 9 of 13

thx mira for ur advances!!
but I'm really confused....the problem is that I need 3 colomn
vectors....so I try to use readline function and fgetl one...
but I can't!!!
the problem is that matlab see empty positions as to disgard them, but
I need that it can see it so that if I want only first, 20th and 21th
colomn values I can get them.

If u can...can u show me how u'd make it with the example I write u in
the past post?

Thx a priori
Angelo

Subject: extract dynamically the headerlines row numvber by string/number

From: Andres

Date: 1 Jul, 2008 15:20:19

Message: 10 of 13

Engeltje <Engeltje81@gmail.com> wrote in message <155421db-
2dae-4c05-a69a-7bd91a8f6793@r66g2000hsg.googlegroups.com>...
[..]
> The problem I had I found a solution using the function
> txt2mat(filename,0,1) I take the first colomn and then I
made a
> function that check if the result vector isnan (in this
case increase
> first index) else increase second index.
> so thx to be interested!
> Now I actually have a new problem!
> I have some data in which part of the colomn is emtpy.
> Example:
>
> timestamp X Y value
> 10
> 20 3.2 3.4 4
> 30
> 40 1.2 2.7 10
>
> I use:
> values=textscan(filename,'%d %f %f %d',
4,'headerlines',1);
>
> [TS,GazePointX,GazePointY,val]=values{:}
>
> the problem is that it stops at TS=10, and the others are
empty
> Can u help me?
> angelo


Hi Angelo,

did you try to use txt2mat with the filename as the only
argument, i.e.

A = txt2mat(filename)

that would give

A =
   10.0000 NaN NaN NaN
   20.0000 3.2000 3.4000 4.0000
   30.0000 NaN NaN NaN
   40.0000 1.2000 2.7000 10.0000

for your example ? txt2mat has built in an automatic header
line and column number detection. If you know the number of
header lines in advance, you can also write

A = txt2mat(filename,1) % or
A = txt2mat(filename,'NumHeaderLines',1)

for a single header line, to be sure.

Hth, regards
Andres

Subject: extract dynamically the headerlines row numvber by string/number

From: Engeltje

Date: 2 Jul, 2008 10:43:05

Message: 11 of 13

On 1 Lug, 17:20, "Andres " <rant...@werb.de> wrote:
> Engeltje <Engeltj...@gmail.com> wrote in message <155421db-
>
> 2dae-4c05-a69a-7bd91a8f6...@r66g2000hsg.googlegroups.com>...
> [..]
>
>
>
> > The problem I had I found a solution using the function
> > txt2mat(filename,0,1) I take the first colomn and then I
> made a
> > function that check if the result vector isnan (in this
> case increase
> > first index) else increase second index.
> > so thx to be interested!
> > Now I actually have a new problem!
> > I have some data in which part of the colomn is emtpy.
> > Example:
>
> > timestamp X Y value
> > 10
> > 20 3.2 3.4 4
> > 30
> > 40 1.2 2.7 10
>
> > I use:
> > values=textscan(filename,'%d %f %f %d',
> 4,'headerlines',1);
>
> > [TS,GazePointX,GazePointY,val]=values{:}
>
> > the problem is that it stops at TS=10, and the others are
> empty
> > Can u help me?
> > angelo
>
> Hi Angelo,
>
> did you try to use txt2mat with the filename as the only
> argument, i.e.
>
> A = txt2mat(filename)
>
> that would give
>
> A =
> 10.0000 NaN NaN NaN
> 20.0000 3.2000 3.4000 4.0000
> 30.0000 NaN NaN NaN
> 40.0000 1.2000 2.7000 10.0000
>
> for your example ? txt2mat has built in an automatic header
> line and column number detection. If you know the number of
> header lines in advance, you can also write
>
> A = txt2mat(filename,1) % or
> A = txt2mat(filename,'NumHeaderLines',1)
>
> for a single header line, to be sure.
>
> Hth, regards
> Andres

Hi Andres!! unfortunally I've just tried it!
the problem is that my file is more complex then the one u've seen!!
if u want to have an idea...if u give me ur emali address I will send
it!
let me know!!
regards angelo

Subject: extract dynamically the headerlines row numvber by string/number

From: Andres

Date: 2 Jul, 2008 13:23:02

Message: 12 of 13

Engeltje <Engeltje81@gmail.com> wrote in message <cb6bb0d2-
fbf2-4fbf-9ec2-d636a39e3d81@p25g2000hsf.googlegroups.com>...
[..]
> if u want to have an idea...if u give me ur emali address
I will send
> it!
> let me know!!
> regards angelo

Hi,
i have just sent you an email. If that does not work,
contact me by the 'Contact Author' link in the file
exchange.
regards
Andres

Subject: extract dynamically the headerlines row numvber by string/number

From: Engeltje

Date: 4 Jul, 2008 15:27:35

Message: 13 of 13

On 2 Lug, 15:23, "Andres " <rant...@werb.de> wrote:
> Engeltje <Engeltj...@gmail.com> wrote in message <cb6bb0d2-
>
> fbf2-4fbf-9ec2-d636a39e3...@p25g2000hsf.googlegroups.com>...
> [..]
>
> > if u want to have an idea...if u give me ur emali address
> I will send
> > it!
> > let me know!!
> > regards angelo
>
> Hi,
> i have just sent you an email. If that does not work,
> contact me by the 'Contact Author' link in the file
> exchange.
> regards
> Andres

Andres...Eureka!!!!!:-D
I finally found a solution.....
reading the file with xlsread.....sometimes solution is easier then
one can think!!!!We look for difficult solution!!!!
Angelo
Thx so much

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us