Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / MATLAB / July 2008



Tip: Looking for answers? Try searching our database.

Parsing Data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Markthomas - 14 Jul 2008 14:14 GMT
Hello all,

  I am trying to parse some data that looks like:

bfleft1=0
bfleft2=378
.
.
.
bfleft298=895
bfleft299=900

and i was wondering what the best way to go about doing
it.  I have other headers other then bfleft# but figured i
could figure it out after i learned how to do it!  I was
guessing i had to search for the "=" then try to get
everything to the left and right.  Thanks a bunch

markthomas
John D'Errico - 14 Jul 2008 14:40 GMT
"Markthomas " <uebermenchens@yahoo.com> wrote in message
<g5fjer$aq6$1@fred.mathworks.com>...
> Hello all,
>
[quoted text clipped - 13 lines]
> guessing i had to search for the "=" then try to get
> everything to the left and right.  Thanks a bunch

But what is your problem? As you say, find the
'=', then proceed.

John
John D'Errico - 14 Jul 2008 14:43 GMT
"Markthomas " <uebermenchens@yahoo.com> wrote in message
<g5fjer$aq6$1@fred.mathworks.com>...
> Hello all,
>
[quoted text clipped - 13 lines]
> guessing i had to search for the "=" then try to get
> everything to the left and right.  Thanks a bunch

Is the problem that you do not know about strtok?

John
Markthomas - 14 Jul 2008 14:56 GMT
"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g5fl57$rpo$1@fred.mathworks.com>...
> "Markthomas " <uebermenchens@yahoo.com> wrote in message
> <g5fjer$aq6$1@fred.mathworks.com>...
[quoted text clipped - 19 lines]
>
> John

I didn't know what command to use to seperate that data...
I guess i have to use strtok but as i seek through the file
with fgetl i also run into lines like:

type=all other combinations

will strtok also handle this??
Markthomas - 14 Jul 2008 15:00 GMT
"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g5fl57$rpo$1@fred.mathworks.com>...
> "Markthomas " <uebermenchens@yahoo.com> wrote in message
> <g5fjer$aq6$1@fred.mathworks.com>...
[quoted text clipped - 19 lines]
>
> John

I didn't know what command to go about seperating the data
to the left and right of the "=".  I guess strtok is the
way to go but i also have to lines that look like:

type=all other combinations

will strtok read this?
John D'Errico - 14 Jul 2008 15:50 GMT
"Markthomas " <uebermenchens@yahoo.com> wrote in message
<g5fm5u$abr$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in
> message <g5fl57$rpo$1@fred.mathworks.com>...
[quoted text clipped - 31 lines]
>
> will strtok read this?

Try it. It is the best way to learn.

thisline = 'type=all other combinations';

[LHS,remainder] = strtok(thisline,'=')

LHS =
type

remainder =
=all other combinations

It appears that strtok leaves the '='. So drop
the first character from remainder.

remainder(1) = [];

John
dpb - 14 Jul 2008 15:32 GMT
...
>    I am trying to parse some data that looks like:
> bfleft1=0
> bfleft2=378
> .
> .
...

See if

  b=textread('yourfile.dat','%*s%d','delimiter','=');

suits...

--
Markthomas - 14 Jul 2008 16:54 GMT
dpb <none@non.net> wrote in message <g5fo6p$au6
$1@aioe.org>...
> ...
> >    I am trying to parse some data that looks like:
[quoted text clipped - 11 lines]
>
> --

I was tried to use the strread command but was not getting
what i wanted:

readin = upper(fgetl(id)) --- i get TYPE=ALL OTHER COMB.
[name value] = strread(readin,'%*s %s','delimeter','=')

but couldn't get it to work... any ideas on this command?
dpb - 14 Jul 2008 19:05 GMT
> dpb <none@non.net> wrote in message <g5fo6p$au6
> $1@aioe.org>...
[quoted text clipped - 21 lines]
>
> but couldn't get it to work... any ideas on this command?

As written you're asking for two return values but telling it to skip
the first and return only one.

You're also asking for a space between the two strings -- whether it
will ignore that or not I didn't test.

Lastly, the line above doesn't match the "title=value" format you asked
about to begin with.  It looks like you may want to use the
'headerlines' option of textread().

Why are you doing it this way instead of reading the whole file, anyway?

If you want the names as well as the values, then

   [n,b]=textread('yourfile.dat','%s%d','delimiter','=');

worked for a sample file of data as in your first posting...

doc textread

--
Markthomas - 14 Jul 2008 19:16 GMT
dpb <none@non.net> wrote in message
<g5g4lq$1ks$1@aioe.org>...
> > dpb <none@non.net> wrote in message <g5fo6p$au6
> > $1@aioe.org>...
[quoted text clipped - 43 lines]
>
> --

the main reason why i can't do the whole file that way is
because there are other data types in the structure of the
file.  besides the numbers there is times, dates, and long
strings that have spaces... i wasn't sure which way to and
be most efficient

Markthomas
Donn Shull - 14 Jul 2008 22:54 GMT
One other tool you may want to consider is regexp.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.