comparison m-toolbox/classes/+utils/@xml/attachNumberToDom.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 attachNumberToDom(number, dom, parent)
3
4 % Store the original shape
5 parent.setAttribute('shape', sprintf('%dx%d', size(number)));
6 parent.setAttribute('type', class(number));
7
8 if isempty(number)
9
10 %%%%% Nothing to do
11 % For example: <parent shape="8x0"/>
12
13 elseif numel(number) == 1
14
15 %%%%% Single number
16 % For example: <parent shape="1x1">1</parent>
17 % <parent shape="1x1">1+3i</parent>
18 if isreal(number)
19 numberStr = sprintf('%.17g', number);
20 else
21 numberStr = ['[', num2str(number, 20), ']'];
22 end
23 content = dom.createTextNode(numberStr);
24 parent.appendChild(content);
25
26 elseif isvector(number) && ...
27 isreal(number) && ...
28 numel(number) <= utils.xml.MAX_DOUBLE_IN_ROW
29
30 %%%%% Real vector which is not longer than 50000 values
31 % For example: <parent shape="1x10">1 2 3 4 5 6 7 8 9 0</parent>
32 content = dom.createTextNode(strtrim(utils.xml.num2str(number)));
33 parent.appendChild(content);
34
35 elseif isvector(number) && ...
36 ~isreal(number) && ...
37 numel(number) <= utils.xml.MAX_IMAG_IN_ROW
38
39 %%%%% imaginary vector which is not longer than 1000 values
40 % For example: <parent shape="1x10">[1+1i 2+1i 3 4-4i ...]</parent>
41 content = dom.createTextNode(strtrim(utils.xml.mat2str(number)));
42 parent.appendChild(content);
43
44 elseif (size(number,1) > 1) && ...
45 (size(number,2) > 1) && ...
46 isreal(number) && numel(number) <= utils.xml.MAX_NUM_IN_MATRIX
47
48 %%%%% Real matrix which have not more than 2500 values
49 % For example: <parent shape="2x3">[1 2 3; 4 5 6]</parent>
50 content = dom.createTextNode(strtrim(utils.xml.mat2str(number)));
51 parent.appendChild(content);
52
53 elseif isvector(number)
54
55 %%%%% General vector
56 % For example: <parent>
57 % <realData type="vector">
58 % <vector> 1 2 3 4 5 6 7 8 9 10 ...</vector>
59 % <vector>11 12 13 14 15 16 17 18 19 20 ...</vector>
60 % </realData>
61 % <imagData type="vector">
62 % <vector> 1 2 3 4 5 6 7 8 9 10 ...</vector>
63 % <vector>11 12 13 14 15 16 17 18 19 20 ...</vector>
64 % </imagData>
65 % </parent>
66 utils.xml.attachVectorToDom(number, dom, parent);
67
68 elseif (size(number,1) > 1) && (size(number,2) > 1)
69
70 %%%%% General matrix
71 % For example: <parent>
72 % <realData type="matrix">
73 % <matrix> 1 2 3 4 5 6 7 8 9 10 ...</matrix>
74 % <matrix>11 12 13 14 15 16 17 18 19 20 ...</matrix>
75 % ...
76 % </realData>
77 % <imagData type="matrix">
78 % <matrix> 1 2 3 4 5 6 7 8 9 10 ...</matrix>
79 % <matrix>11 12 13 14 15 16 17 18 19 20 ...</matrix>
80 % ...
81 % </imagData>
82 % </parent>
83 utils.xml.attachMatrixToDom(number, dom, parent);
84
85 else
86
87 error('### Should not happen. Size of the input object %dx%d', size(number))
88
89 end
90
91 end
92