我需要在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解决方案。