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:
read mixed text, data file and find corresponding data values

Subject: read mixed text, data file and find corresponding data values

From: Jiazhu Hu

Date: 16 Mar, 2008 03:56:03

Message: 1 of 3

Hello, could you help take a look my trouble for reading
mixed text, data file. Thanks.

I have many *.txt files (each file corresponding a
condition) like:
--------------------------start
Text Line 1
---
Text line n

Coordinates
Point 1
X 9 Y 10 Z 8

Text Line 1
---
Text line n

Coordinates
Point 2
X 1 Y 10 Z 8

Force
point 1
Direction
X Y Z
units Newton 10 20 30
----------------------------end

The number of text lines 'n' for different *.txt files is
not the dame. However, the relative positions between the
numeric value and its name flag, eg, 10 20 30 and Force,
is fixed in all files.


How I can get the corresponding coordinates for Point 1 (9
10 8) and Point 2 (1 10 8) and the Force values 10 20 30
for Point 1 by reading this *.txt file using function like

Read *.txt
if string ==Coordinates
 if string_in_next_line==point 1
    if string=x,Coordinate(1,1)=9
       else if string = y,Coordinate(1,2)=10
       else string==z,Coordinate(1,2)=8
     end
  elseif string_in_next_line==point 2
-------------------similar for point 2
elseif string ==force
 if
 -------------similar for trying to get force values and
corresponding point and direction infor.
end

Subject: read mixed text, data file and find corresponding data values

From: Amir

Date: 16 Mar, 2008 16:39:05

Message: 2 of 3

Read the whole file into a string variable, and then use
regexp to parse it.
Help regexp

Also, the Matlab Help has many good pages of help on
regexp.

"Jiazhu Hu" <yuanxin1999@hotmail.com> wrote in message
<fri5oj$p2a$1@fred.mathworks.com>...
> Hello, could you help take a look my trouble for reading
> mixed text, data file. Thanks.
>
> I have many *.txt files (each file corresponding a
> condition) like:
> --------------------------start
> Text Line 1
> ---
> Text line n
>
> Coordinates
> Point 1
> X 9 Y 10 Z 8
>
> Text Line 1
> ---
> Text line n
>
> Coordinates
> Point 2
> X 1 Y 10 Z 8
>
> Force
> point 1
> Direction
> X Y Z
> units Newton 10 20 30
> ----------------------------end
>
> The number of text lines 'n' for different *.txt files
is
> not the dame. However, the relative positions between
the
> numeric value and its name flag, eg, 10 20 30 and Force,
> is fixed in all files.
>
>
> How I can get the corresponding coordinates for Point 1
(9
> 10 8) and Point 2 (1 10 8) and the Force values 10 20 30
> for Point 1 by reading this *.txt file using function
like
>
> Read *.txt
> if string ==Coordinates
> if string_in_next_line==point 1
> if string=x,Coordinate(1,1)=9
> else if string = y,Coordinate(1,2)=10
> else string==z,Coordinate(1,2)=8
> end
> elseif string_in_next_line==point 2
> -------------------similar for point 2
> elseif string ==force
> if
> -------------similar for trying to get force values and
> corresponding point and direction infor.
> end

Subject: read mixed text, data file and find corresponding data values

From: Miroslav Balda

Date: 16 Mar, 2008 19:32:03

Message: 3 of 3

"Jiazhu Hu" <yuanxin1999@hotmail.com> wrote in message
<fri5oj$p2a$1@fred.mathworks.com>...

SNIP

This is very often question. I can recommend to use the
function ffread from FEX (Id 9034), which is suitable just
for this type of tasks.

Mira

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