Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@xml/getVector.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 | |
2 function values = getVector(node) | |
3 | |
4 shape = utils.xml.getShape(node); | |
5 realValues = []; | |
6 imagValues = []; | |
7 | |
8 for jj = 1:node.getLength() | |
9 | |
10 childNode = node.item(jj-1); | |
11 if childNode.getNodeType == childNode.ELEMENT_NODE | |
12 | |
13 % Get node name | |
14 dataType = utils.xml.mchar(childNode.getNodeName()); | |
15 | |
16 if strcmp(dataType, 'realData') | |
17 | |
18 % Get real data | |
19 realValues = getValues(childNode); | |
20 | |
21 elseif strcmp(dataType, 'imagData') | |
22 | |
23 % Get imaginary data | |
24 imagValues = getValues(childNode); | |
25 | |
26 else | |
27 | |
28 error('### Unexpected Node: %s', dataType); | |
29 | |
30 end | |
31 | |
32 end | |
33 end | |
34 | |
35 % Combine the values to complex numbers if necessary | |
36 if ~isempty(imagValues) | |
37 values = complex(realValues, imagValues); | |
38 else | |
39 values = realValues; | |
40 end | |
41 | |
42 % Reshape the values | |
43 values = reshape(values, shape); | |
44 | |
45 end | |
46 | |
47 function values = getValues(node) | |
48 | |
49 values = []; | |
50 | |
51 % Collect all vectors | |
52 for nn = 1:node.getLength() | |
53 vectorNode = node.item(nn-1); | |
54 if vectorNode.getNodeType == vectorNode.ELEMENT_NODE | |
55 | |
56 values = [values sscanf(utils.xml.mchar(vectorNode.getTextContent()), '%g ', [1,inf])]; | |
57 type = utils.xml.getType(vectorNode); | |
58 | |
59 end | |
60 end | |
61 | |
62 % cast to other number type (if necessary) | |
63 values = cast(values, type); | |
64 | |
65 end | |
66 |