2017-06-06 63 views
0

我正在处理两列文本文件,并且希望将单列中excel文件中两列的减法结果保存在一张表中。我从事的是以下代码,但下面的程序将差异写入单独工作簿中的单独工作表中,并且我需要在单个工作表中全部使用50(差异)。请帮帮我。谢谢。使用MATLAB将数据写入单张excel中

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 

回答

1

您可以将所有结果存储到矩阵中,然后写入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)