# Subtract data from two columns and show result in 3rd column

27 views (last 30 days)
KRUNAL on 23 Jul 2014
Edited: Benjamin on 15 Apr 2019
I have the following data in an excel sheet
A B C
736 373
734 371
725 364
719 361
711 353
706 347
699 342
689 337
680 327
676 318
So basically I want to run this as A(1) - B(1),A(2) - B(2)..A(n) -B(n) and it should create the outputs at C1, C2...Cn respectively. Can anyone help me on this?
Benjamin on 15 Apr 2019
But in every loop, if the size of the matrix (output here) changes Matlab gives error of different matrix sizes. Is there anysolution for that.
FYI: my Matlab code generates a matrix of [A] = n*2 and in every loop (for i = 1:10) n changes. I would like to store all A results in another B matrix.

Joseph Cheng on 23 Jul 2014
A(:,3) = A(:,1)-A(:,2);
xlswrite(____)
Joseph Cheng on 23 Jul 2014
Why is there a for loop? does dstfile change base on the loop? Also if it outputs is in AC, AD, and AE what is the size of the Y array? is it one column or 3?

KRUNAL on 23 Jul 2014
I wrote the code as follows :
for i=2:11
X(:,3) = X(:,2)-X(:,1);
Y = num2str (X(:,3));
if (Y > 300)
Y = {'ok'};
xlswrite (dstfile,Y,sheet,'AC');
else
Y = {'Check'};
xlswrite (dstfile,Y,sheet,'AC');
end
end
But it is updating only cell AC1 and it is writing "check" in that cell.Can anyone suggest where I am going wrong?
##### 2 CommentsShowHide 1 older comment
KRUNAL on 23 Jul 2014
ok..got my mistake. Finally the code is running..thank you