comparison m-toolbox/classes/+utils/@xml/getMatrix.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 = getMatrix(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 matrix lines
52 for nn = 1:node.getLength()
53 matrixNode = node.item(nn-1);
54 if matrixNode.getNodeType == matrixNode.ELEMENT_NODE
55
56 values = [values; sscanf(utils.xml.mchar(matrixNode.getTextContent()), '%g ', [1,inf])];
57 type = utils.xml.getType(matrixNode);
58
59 end
60 end
61
62 % cast to other number type (if necessary)
63 values = cast(values, type);
64
65 end
66