您的位置:首页 > 编程语言 > MATLAB

matlab下生成的矩阵存入xml文件中

2017-04-28 19:30 941 查看
参考:http://blog.csdn.net/wzy1990/article/details/8508662

 % name是输入的文件名,data是matlab中的矩阵

function createxml(name,datatest)

xdoc=com.mathworks.xml.XMLUtils.createDocument('opencv_storage');  

xroot=xdoc.getDocumentElement;  

%  

[m,n]=size(datatest);  

type=xdoc.createElement(name);  

xroot.appendChild(type);  

type.setAttribute('type_id','opencv-matrix')  

%  

rows=xdoc.createElement('rows');  

rows.appendChild(xdoc.createTextNode(sprintf('%d',m)));  

type.appendChild(rows); 

cols=xdoc.createElement('cols');  

cols.appendChild(xdoc.createTextNode(sprintf('%d',n)));  

type.appendChild(cols);  

dt=xdoc.createElement('dt');  

dt.appendChild(xdoc.createTextNode(sprintf('%s','f')));  

type.appendChild(dt);  

//写入数据

data=xdoc.createElement('data'); 

data.appendChild(xdoc.createTextNode(sprintf('%10.8f ',datatest)));  

type.appendChild(data);  

//或者一下注释的这段

% for i=1:m

%      for j=1:n

%      data.appendChild(xdoc.createTextNode(sprintf('%10.8f  ',datatest(i,j))));

%      end

% end

% type.appendChild(data);

str=strcat(name,'.xml');  

xmlwrite(str,xdoc);  

end  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: