在Matlab中将标题添加到矩阵 [英] Adding a header to a matrix in Matlab
问题描述
我希望你们到目前为止过的愉快.我意识到您不能在MATLAB中将字符串标题添加到数值矩阵中.我正在尝试将标头添加到当前具有的矩阵中,并将其输出到制表符分隔的文本文件中.根据我的研究,我知道必须将矩阵转换为单元格,但是使用dlmwrite保存单元格时遇到了麻烦.
I hope you guys are having a nice Tuesday so far. I realize that you cannot add a string header to a numerical matrix in MATLAB. I am trying to add headers to a matrix I currently have and output it to a tab-delimited text file. From my research, I know that the matrix has to be converted into a cell, but I am having trouble saving the cell using dlmwrite.
这是我当前拥有的矩阵:
Here is the matrix I currently have:
0 0 0
0.0454 0.0105 0.0105
0.0907 0.0066 0.0068
0.1814 0.0038 0.0049
0.3629 0.0034 0.0040
0.7258 0.0029 0.0023
1.4515 0.0002 0.0007
2.9030 0.0003 0.0005
这就是我想要的:
tau TOL Adev FOL Adev
0.0454 0.0105 0.0105
0.0907 0.0066 0.0068
0.1814 0.0038 0.0049
0.3629 0.0034 0.0040
0.7258 0.0029 0.0023
1.4515 0.0002 0.0007
2.9030 0.0003 0.0005
矩阵(第一行中的3,7为零)称为saveData.
The matrix(3, 7 with zeros in the first row) is called saveData.
我尝试分配标头= ['tau','TOL Adev','FOL Adev'];并输出= {header; saveData};但是我不知道如何使用dlmwrite('filename',output,'\ t').
I have tried assigning header = ['tau', 'TOL Adev', 'FOL Adev']; and output = {header;saveData}; but I cannot figure out how to use dlmwrite('filename', output, '\t').
非常感谢您的帮助! -亚历克斯
Thank you so much for the help! -Alex
推荐答案
如果您感到懒惰并且矩阵不太大,则可以将数据制作为数据集,然后将其导出.如果矩阵很大,建议您查看Amro给出的链接.注释数据集是统计工具箱中的功能.
If you are feeling lazy and your matrix is not too big, you can make your data into a dataset, then export it. If your matrix is large, I recommend you look at the link Amro has given. Note dataset is a function in the Statistics Toolbox.
ds = dataset({rand(10,3) 'a' 'b' 'c'})
export(ds, 'file', 'foo.txt', 'delim', '\t');
这篇关于在Matlab中将标题添加到矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!