comparison m-toolbox/classes/+utils/@xml/attachMatrixToDom.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 attachMatrixToDom(numbers, dom, parent)
3
4 shape = sprintf('%dx%d', size(numbers));
5
6 % REMARK: It is not possible to name the type 'matrix' because 'matrix'
7 % is also a class name.
8
9 %%%%% Real data %%%%%
10 realNode = dom.createElement('realData');
11 realNode.setAttribute('type', 'doubleMatrix');
12 realNode.setAttribute('shape', shape);
13
14 %%% Set the parent attribute 'type' to doubleMatrix
15 parent.setAttribute('type', 'doubleMatrix');
16 parent.appendChild(realNode);
17
18 for ii = 1:size(numbers,1)
19
20 number_str = strtrim(utils.xml.num2str(real(numbers(ii,:))));
21 if ~isempty(number_str)
22 %%% Create new matrix node
23 content = dom.createTextNode(number_str);
24 matrixNode = dom.createElement('doubleMatrix');
25 matrixNode.setAttribute('type', class(numbers));
26 matrixNode.appendChild(content);
27 realNode.appendChild(matrixNode);
28 end
29 end
30
31 %%%%% Imaginary data %%%%%
32 if ~isreal(numbers)
33 imagNode = dom.createElement('imagData');
34 imagNode.setAttribute('type', 'doubleMatrix');
35 imagNode.setAttribute('shape', shape);
36 parent.appendChild(imagNode);
37 for ii = 1:size(numbers,1)
38 number_str = strtrim(utils.helper.num2str(imag(numbers(ii,:))));
39 if ~isempty(number_str)
40 %%% Create new matrix node
41 content = dom.createTextNode(number_str);
42 matrixNode = dom.createElement('doubleMatrix');
43 matrixNode.setAttribute('type', class(numbers));
44 matrixNode.appendChild(content);
45 imagNode.appendChild(matrixNode);
46 end
47 end
48 end
49
50 end