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:
Textscan parameters

Subject: Textscan parameters

From: Sebastian Gatzka

Date: 22 May, 2008 07:52:02

Message: 1 of 6

Hello World.

I'm trying to read some data from a text-file.

First problem: When trying to open the file with
 >> fid=open('elements_1h.dat');
the Import-Wizard is starting. Why is that?

Second Problem: How do I have to specify the 'headerLines'
parameter?

There are 8 lines of header stuff in the file, so I tried to
read like this:

 >> C=textscan(fid,'%d16 %d16 %d16 %d16','headerLines','8',1)

The file looks like this after the header:

       1 622 534 535
       2 366 534 622
       3 997 930 996
       4 931 930 997
       5 949 910 826
       6 911 910 949
       ...

And of course there is an error message:

------------------------------------------------------------------------
       Segmentation violation detected at
----------------------------------------------------------

Any ideas?

Greetings. S.

Subject: Textscan parameters

From: Pekka

Date: 22 May, 2008 08:58:01

Message: 2 of 6

"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@stud.tu-
darmstadt.de> wrote in message
<g138n2$s6i$1@fred.mathworks.com>...
> Hello World.
>
> I'm trying to read some data from a text-file.
>
> First problem: When trying to open the file with
> >> fid=open('elements_1h.dat');
> the Import-Wizard is starting. Why is that?
>
> Second Problem: How do I have to specify the 'headerLines'
> parameter?
>
> There are 8 lines of header stuff in the file, so I tried
to
> read like this:
>
> >> C=textscan(fid,'%d16 %d16 %d16
 %d16','headerLines','8',1)
>
> The file looks like this after the header:
>
> 1 622 534 535
> 2 366 534 622
> 3 997 930 996
> 4 931 930 997
> 5 949 910 826
> 6 911 910 949
> ...
>
> And of course there is an error message:
>
> ----------------------------------------------------------
--------------
> Segmentation violation detected at
> ----------------------------------------------------------
>
> Any ideas?
>
> Greetings. S.

Textscan needs a file identifier fid, which you get from
fopen, not open, it's another thing
doc textscan, there are examples also
Try
fid=fopen('elements_1h.dat','rt');

Headerlines parameter wants a number value 8, not string '8'
C=textscan(fid,'%d16 %d16 %d16 %d16','headerLines',8);

hope this helps

Subject: Textscan parameters

From: Sebastian Gatzka

Date: 23 May, 2008 10:50:03

Message: 3 of 6

Thats what I needed!
Thank you!

Subject: Textscan parameters

From: Sebastian Gatzka

Date: 25 May, 2008 16:42:01

Message: 4 of 6

Another question.

How can I read files which contain many 'blocks' like this:

     deltaT = 0.001
     Time = 0.001

     barycenter at time 0.001 s is 0.3 m
     ExecutionTime = 2.61 s ClockTime = 3 s

I need the values of 'time' and the 'location of the
barycenter'. In this case 0.001s and 0.3m.

So there are many lines and characters to skip.

How can this be done?

Subject: Textscan parameters

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 25 May, 2008 17:34:21

Message: 5 of 6

In article <g1c4sp$sk7$1@fred.mathworks.com>,
Sebastian Gatzka <sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote:
>Another question.

>How can I read files which contain many 'blocks' like this:

> deltaT = 0.001
> Time = 0.001

> barycenter at time 0.001 s is 0.3 m
> ExecutionTime = 2.61 s ClockTime = 3 s

>I need the values of 'time' and the 'location of the
>barycenter'. In this case 0.001s and 0.3m.

>So there are many lines and characters to skip.

>How can this be done?

I'd be tempted just to read in the entire file into a single
variable, and then to use the regexp facilities to extract
the information I was looking for.

That or tempted to write a little perl routine that did the same
kind of extraction, outputing into a form that was easier to read.

--
  "The quirks and arbitrariness we observe force us to the
  conclusion that ours is not the only universe." -- Walter Kistler

Subject: Textscan parameters

From: Sebastian Gatzka

Date: 26 May, 2008 17:58:02

Message: 6 of 6

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g1c7ut$8mj$1@canopus.cc.umanitoba.ca>...
> In article <g1c4sp$sk7$1@fred.mathworks.com>,
> Sebastian Gatzka
<sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote:
> >Another question.
>
> >How can I read files which contain many 'blocks' like this:
>
> > deltaT = 0.001
> > Time = 0.001
>
> > barycenter at time 0.001 s is 0.3 m
> > ExecutionTime = 2.61 s ClockTime = 3 s
>
> >I need the values of 'time' and the 'location of the
> >barycenter'. In this case 0.001s and 0.3m.
>
> >So there are many lines and characters to skip.
>
> >How can this be done?
>
> I'd be tempted just to read in the entire file into a single
> variable, and then to use the regexp facilities to extract
> the information I was looking for.
>
> That or tempted to write a little perl routine that did
the same
> kind of extraction, outputing into a form that was easier
to read.
>
> --
> "The quirks and arbitrariness we observe force us to the
> conclusion that ours is not the only universe." --
Walter Kistler


I have read the help for regexp four times now, but I don't
think I understand it.

What do I do with the numbers this tool is outputting?

And what is a perl routine?

Tags for 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