fprintf(fileID, fmt, CELL{:});
Add header to data file
3 次查看(过去 30 天)
显示 更早的评论
Hello,
In my code below, I wanted to know how to go about adding a header to the file. The header will be the column names:
A B C D E. Thanks for your time and help. Here is my code:
A = 1:15;
B = (0.5)*rand(15,1);
C = 1:20;;
D = (0.5)*rand(20,1);
E = (0.5)*rand(20,1);
CELL{1} = A';
CELL{2} = B;
CELL{3} = C';
CELL{4} = D;
CELL{5} = E;
Astr = cell(20,5);
Astr = cellstr(num2str(A.', '%6.0f'));
Output(1:length(Astr), 1) = Astr;
Astr = cellstr(num2str(B, '%6.5f'));
Output(1:length(Astr), 2) = Astr;
Astr = cellstr(num2str(C.', '%6.0f'));
Output(1:length(Astr), 3) = Astr;
Astr = cellstr(num2str(D, '%6.5f'));
Output(1:length(Astr), 4) = Astr;
Astr = cellstr(num2str(E, '%6.5f'));
Output(1:length(Astr), 5) = Astr;
fileID = fopen('check.dat','wt');
fmt = '%s,%s,%s,%s,%s\n';
OutTranspose = Output .'; %need to transpose it
fprintf(fileID, fmt, OutTranspose{:});
fclose(fileID);
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!