text
2 次查看(过去 30 天)
显示 更早的评论
I have a matrix whixh i am converting to a .txt file, I need to include a header so that each column in the matrix can be defined when looking at the .txt file, how can this be done i.e. I need a different header for each column in the matrix, such as the first column is temp1, the second is temp2 and so on?
cheers
1 个评论
Jan
2011-11-17
How do you convert the matrix to a txt file? What have you tried so far? Which problem did occur?
回答(1 个)
Jan
2011-11-17
I do not understand the problem. Perhaps this helps:
Header = {'temp1', 'temp2', 'temp3'};
Data = rand(10, 3);
FID = fopen(fullfile(tempdir, 'test.txt'), 'w');
if FID == -1, error('Cannot open file'); end
fprintf(FID, '%-20s', Header{:});
fprintf(FID, '\n');
Fmt = [repmat('%-20g', 1, 3), '\n'];
fprintf(FID, Fmt, transpose(Data));
fclose(FID);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!