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

27 views (last 30 days)

Show older comments

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?

##### 4 Comments

Benjamin
on 15 Apr 2019

thanks for this helpful answer.

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.

### Accepted Answer

Joseph Cheng
on 23 Jul 2014

Read in the data using xlsread() and write it with xlswrite

A = xlsread(____);

A(:,3) = A(:,1)-A(:,2);

xlswrite(____)

##### 7 Comments

Joseph Cheng
on 23 Jul 2014

### More Answers (1)

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!