【发布时间】:2010-12-29 19:01:27
【问题描述】:
我需要将数据写入 MATLAB 中的 .txt 文件。我知道如何编写字符串 (fprintf) 或 矩阵 (dlmwrite),但我需要一些可以同时做到这两个的东西。下面我举个例子:
str = 'This is the matrix: ' ;
mat1 = [23 46 ; 56 67] ;
%fName
if *fid is valid*
fprintf(fid, '%s\n', str)
fclose(fid)
end
dlmwrite(fName, *emptymatrix*, '-append', 'delimiter', '\t', 'newline','pc')
dlmwrite(fName, mat1, '-append', 'newline', 'pc')
这工作正常,但有一个问题。文件的第一行是:
This is the matrix: 23,46
这不是我想要的。我想看:
This is the matrix:
23 46
56 67
我该如何解决这个问题?我不能使用 for 循环和 printf 解决方案,因为数据量很大而且时间是个问题。
【问题讨论】:
标签: string matlab matrix file-io text-files