uData是带有数字的30x5矩阵。 name_Database是一个30x1的单元格数组,其中包含名称字符串(例如假冒主题1,假冒主题2,Bob)。 什么会修复代码以使数据对齐? (请参见图片中的错位)。
ID = dbedit.uData(:,1);
scE = dbedit.uData(:,2);
ccE = dbedit.uData(:,3);
scC = dbedit.uData(:,4);
ccC = dbedit.uData(:,5);
names = dbedit.name_Database;
% Text file to output data into is called uDatabase.txt file.
output_file = 'uDatabase.txt';
% Open file for writing
fid = fopen(output_file, 'w+');
% Header
fprintf(fid, '%6s %12s %18s %24s %30s %36s\n', 'Name', 'ID', 'scE',...
'ccE', 'scC', 'ccC');
% Write the data.
for ii=1:numel(names)
fprintf(fid, '%6s %12.0f %18.0f %24.0f %30.0f %36.0f\n',names{ii},...
ID(ii),scE(ii),ccE(ii),scC(ii),...
ccC(ii));
end
% Close the .txt file.
fclose(fid);
输出图片:
Name ID scE ccE scC ccC
Fake Subject 1 1 3 4 5 2
Fake Subject 2 2 4 3 2 5
Fake Subject 3 3 1 6 6 1
Fake Subject 4 4 2 5 3 4
Fake Subject 5 5 3 4 4 3
Fake Subject 6 6 6 1 1 6
Fake Subject 7 7 7 0 1 6
Fake Subject 8 8 4 3 3 4
Fake Subject 9 9 2 5 5 2
Fake Subject 10 10 5 2 4 3
Fake Subject 11 11 6 1 3 4
Fake Subject 12 12 5 2 2 5
Fake Subject 13 13 1 6 3 4
Fake Subject 14 14 3 4 4 3
Fake Subject 16 15 2 5 3 4
Fake Subject 17 16 1 6 1 6
Fake Subject 18 17 4 3 3 4
Fake Subject 19 18 2 5 5 2
Fake Subject 20 19 6 1 5 2
Fake Subject 21 20 3 4 1 6
Fake Subject 22 21 3 4 3 4
Fake Subject 23 22 5 2 1 6
Fake Subject 24 23 3 4 1 6
Fake Subject 25 24 7 0 3 3
Fake Subject 26 25 3 4 3 4
Fake Subject 27 26 0 0 0 0
Fake Subject 15 27 4 3 3 3
Bob 28 6 1 2 5
ludba 29 4 3 4 3
Test Subject 2 30 0 0 0 0