Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@xml/getNumber.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 = getNumber(node) | |
3 | |
4 shape = utils.xml.getShape(node); | |
5 type = utils.xml.getType(node); | |
6 | |
7 if any(shape==0) | |
8 | |
9 % Special case for an empty double. | |
10 values = zeros(shape); | |
11 | |
12 else | |
13 | |
14 if strcmp(type, 'double') || strncmp(type, 'uint', 4) || strncmp(type, 'int', 3) || ... | |
15 strcmp(type, 'single') || strcmp(type, 'float') || strcmp(type, 'logical') | |
16 | |
17 % Get the values direct from the node content | |
18 numberStr = utils.xml.mchar(node.getTextContent()); | |
19 if (numberStr(1) == '[') | |
20 values = eval(numberStr); | |
21 else | |
22 values = sscanf(numberStr, '%g '); | |
23 end | |
24 | |
25 % Cast to correct type | |
26 if ~strcmp(type, 'double') | |
27 values = cast(values, type); | |
28 end | |
29 | |
30 elseif strcmp(type, 'doubleVector') | |
31 | |
32 % Get vector | |
33 values = utils.xml.getVector(node); | |
34 | |
35 elseif strcmp(type, 'doubleMatrix') | |
36 | |
37 % Get matrix | |
38 values = utils.xml.getMatrix(node); | |
39 | |
40 else | |
41 | |
42 error('### Unknown number type [%s]', type); | |
43 | |
44 end | |
45 | |
46 % Reshape the values | |
47 values = reshape(values, shape); | |
48 | |
49 end | |
50 | |
51 end |