我想在Matlab中用逗号来分隔文本文件中的字符串,到目前为止,我已经使用了 "csvwrite "和 "dlmwrite"。
它们一般采取这种形式。
myFile - input ('Please enter file's directory','s');
readMatrix - csvread(myFile);
csvwrite('newdatafile.dat', readMatrix);
澄清一下,我想做的事情是这样的。
转一个文本文件,看起来像这样。
为了这个。
0.3,
0.1,
0.5,
为什么你需要在行尾加上逗号? csvread 也适用于行间包含逗号分隔的文件,即。
file1.dat: 02, 04, 06, 08, 10, 12 03, 06, 09, 12, 15, 18 05, 10, 15, 20, 25, 30 07, 14, 21, 28, 35, 42 11, 22, 33, 44, 55, 66 --and then in matlab: readMatrix = csvread('file1.dat')
将读取文件,结果是
(尽管每行末尾缺少逗号) 如果文件只包含一列数字(因此没有逗号),同样的情况也适用。size(readMatrix) = [5 6]
然而,如果你真的想要这些逗号,你可以自己用fprintf读取数据并打印到一个文件中。