使用MATLAB将数据写入单张excel

我正在处理两列文本文件,并希望将一个excel文件中的两列相减的结果保存在一张表中。 我在下面的代码工作,但下面的程序是写在单独的工作簿单独的工作表中的差异,我需要在一个工作表中的所有50(差异)。 请帮帮我。 谢谢。

close all; for k = 1:9 filename = sprintf('Data_F_Ind000%d.txt',k); data = load (filename); f = data(:,1) - data (:,2); xlswrite('difference_1_9.xlsx',f,1); end 

您可以将所有结果存储到matrix中,然后写入excel。 检查下面的伪代码。

 N = 10 ; % your number of lines in data/ each file nfiles = 9 ; % number of files iwant = zeros(N,nfiles) ; for i = 1:nfiles data = rand(N,2) ; iwant(:,i) = data(:,1)-data(:,2) ; end myfile = 'myfile.xlsx' ; xlswrite(myfile,iwant)