4
当我使用下面的代码。我得到正确导出的数字数据,但是当每列的第一行应该有标题(标题)时,第一行是空白的。任何解决方案matlab,如何将文本和数字数据导出到excel csv文件?
clc
clear
filename = 'file.csv';
fileID = fopen(filename,'wt');
%**************************************************************************
%Sample data (note sample data are transposed row, i.e. columns)
sample1 = [1,2,3,4]';
sample2 = [332.3, 275.8, 233.3, 275]';
sample3 = [360, 416.7, 500, 360]';
sample4= [-0.9, -0.9, -0.9, -0.9]';
sample5 = [ 300000, 0, 0, 0]';
A ={'text1','text2', 'text3', 'text4', 'text5'}; %'
%***************************************************************************
%write string to csv
[rows, columns] = size(A);
for index = 1:rows
fprintf(fileID, '%s,', A{index,1:end-1});
fprintf(fileID, '%s\n', A{index,end});
end
fclose(fileID);
%***************************************************************************
%write numerical data to csv
d = [sample1, sample2, sample3, sample4, sample5];
csvwrite(filename, d, 1);
标头工作正常,但数据没有正确写入。我只得到2行随机数据 – user1945925
确实,它覆盖了数字数据,它看起来像dlmwrite是更好的选择反正... –
你有没有运气让文本和数字数据正确显示在CSV文件上?我可以得到或者。但不正确。谢谢! – user1945925