【问题标题】:extracting data from within xml files using MATLAB使用 MATLAB 从 xml 文件中提取数据
【发布时间】:2011-10-06 03:00:06
【问题描述】:

我是一名尝试学习 MATLAB 的完整编程初学者。我想从一堆不同的 xml 文件中提取数值数据。数值数据项由标签 和 界定。如何在 MATLAB 中编写程序?

我的算法:

1. Open the folder
2. Look into each of 50 xml files, one at a time
3. Where the tag <HNB.1></HNB.1> exists, copy numerical contents between said tag and write results into a new file
4. The new file name given for step 3 should be the same as the initial file name read in Step 2, being appended with "_data extracted"

示例:

FileName = Stewart.xml
Contents = blah blah blah <HNB.1>2</HNB.1> blah blah
NewFileName = Stewart_data extracted.txt
Contents = 2

【问题讨论】:

标签: matlab file-io


【解决方案1】:

假设你想读取这个文件:

<PositiveSamples numImages="14">
<image numSubRegions="2" filename="TestingScene.jpg">
	<subregion yStart="213" yEnd="683" xStart="1" xEnd="236"/>
	<subregion yStart="196" yEnd="518" xStart="65" xEnd="226"/>
</image>
</PositiveSamples>

然后在matlab中,读取文件内容如下:

%read xml file
xmlDoc = xmlread('PositiveSamples.xml');

%Get root element
root = xmlDoc.getDocumentElement();

%Read attributevale
numOfImages = root.getAttribute('numImages');
numOfImages = char(numOfImages);   
numOfImages = uint16(eval(numOfImages));

【讨论】:

    【解决方案2】:

    MATLAB中读取xml数据的基本函数是xmlread;但如果你是一个完整的初学者,那么使用它可能会很棘手。试试this series of blog postings,它会告诉你如何将它们组合在一起。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多