0

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

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.