Mercurial > hg > ltpda
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@xml/attachMatrixToDom.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,50 @@ + +function attachMatrixToDom(numbers, dom, parent) + + shape = sprintf('%dx%d', size(numbers)); + + % REMARK: It is not possible to name the type 'matrix' because 'matrix' + % is also a class name. + + %%%%% Real data %%%%% + realNode = dom.createElement('realData'); + realNode.setAttribute('type', 'doubleMatrix'); + realNode.setAttribute('shape', shape); + + %%% Set the parent attribute 'type' to doubleMatrix + parent.setAttribute('type', 'doubleMatrix'); + parent.appendChild(realNode); + + for ii = 1:size(numbers,1) + + number_str = strtrim(utils.xml.num2str(real(numbers(ii,:)))); + if ~isempty(number_str) + %%% Create new matrix node + content = dom.createTextNode(number_str); + matrixNode = dom.createElement('doubleMatrix'); + matrixNode.setAttribute('type', class(numbers)); + matrixNode.appendChild(content); + realNode.appendChild(matrixNode); + end + end + + %%%%% Imaginary data %%%%% + if ~isreal(numbers) + imagNode = dom.createElement('imagData'); + imagNode.setAttribute('type', 'doubleMatrix'); + imagNode.setAttribute('shape', shape); + parent.appendChild(imagNode); + for ii = 1:size(numbers,1) + number_str = strtrim(utils.helper.num2str(imag(numbers(ii,:)))); + if ~isempty(number_str) + %%% Create new matrix node + content = dom.createTextNode(number_str); + matrixNode = dom.createElement('doubleMatrix'); + matrixNode.setAttribute('type', class(numbers)); + matrixNode.appendChild(content); + imagNode.appendChild(matrixNode); + end + end + end + +end