Reputation: 105
I am working on two column text file and want to save the result of subtraction of two columns in a excel file in a single sheet. I worked on following code but the program below is writing the difference in separate sheet in a single workbook, and I need all 50 (difference) in a single sheet. Please help me. Thank you.
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
Upvotes: 0
Views: 41
Reputation: 1241
You can store all your results into a matrix and then after write to excel. Check the below pseudo code.
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)
Upvotes: 1