Path: news.mathworks.com!not-for-mail
From: "Donn Shull" <donn.shull.no_spam@aetoolbox.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: strings and files and concatenations
Date: Thu, 13 Aug 2009 03:19:05 +0000 (UTC)
Organization: L &#38; D Engineering LLC
Lines: 65
Message-ID: <h600n9$11k$1@fred.mathworks.com>
References: <31f96cfe-2edb-4e72-bfe4-b82160584ea4@2g2000prl.googlegroups.com>
Reply-To: "Donn Shull" <donn.shull.no_spam@aetoolbox.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250133545 1076 172.30.248.38 (13 Aug 2009 03:19:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Aug 2009 03:19:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 219306
Xref: news.mathworks.com comp.soft-sys.matlab:562885


Andrew <andrewkgentile@gmail.com> wrote in message <31f96cfe-2edb-4e72-bfe4-b82160584ea4@2g2000prl.googlegroups.com>...
> Below is a very abbreviated chunk of a much larger data file.  I want
> to write some code which will search through this file and pull all
> the values shown between <Quad> and <\Quad>.  There are hundreds of
> these sets of data in each file, and so I also want to assign a name
> or number to this set of data.  The name of the set is slot 1, which
> is shown in the first line below.  Can someone please explain how to
> pull the values out of this file?  I know how to use fopen, and a few
> string functions.  I have been able to find all the lines with <Quad>
> in it, but I can't figure out how to pull the values out or the string
> name.  Any help would be appreciated.  Thanks.
> 
> <SlotData slot="001">
> <Notes></Notes>
> <Display>yes</Display>
> <ForwardExciter>
> <Range>4A</Range>
> <SpuPhaseData>0886</SpuPhaseData>
> <SpuCalData>0810</SpuCalData>
> <Quad>0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, </Quad>

Hi Andrew,

This would appear to be an XML file, so I would suggest using xmlread to read it. For example if this were a file named SlotData.xml then

dom = xmlread('SlotData.xml')

would create a dom node. Then you can use the xml dom methods to extract the information you want.

>> doc = dom.getDocumentElement
 
doc =
 
[SlotData: null]

>> slotNumber = str2num(doc.getAttribute('slot'))

slotNumber =

     1

You can get a list of the Quad nodes with:

>> quadList = doc.getElementsByTagName('Quad')
 
quadList =
 
org.apache.xerces.dom.DeepNodeListImpl@1429c57

The length of the list is given by:

>> quadList.getLength

and you could process them with a loop
for index = 0:quadList.getLength-1
    quadText(index+1) = quadList.item(index).getTextContent
    % place processing commands here
end

Hope this helps,

Donn