フィルターのクリア

Add header to data file

1 回表示 (過去 30 日間)
monkey_matlab
monkey_matlab 2016 年 1 月 7 日
回答済み: Walter Roberson 2016 年 1 月 7 日
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);

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 1 月 7 日
fprintf(fileID, fmt, CELL{:});

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by