Swaroop
Swaroop

Reputation: 9

Sum up two MAT files

I am trying to add/sum/merge two MAT files. Both the files contain only numeric values. Basically like this: 'file_1' contains

2 0 2 0 1 0...
3 0 9 0 2 0...
1 0 6 0 7 0...
...

'file_2.mat' contains

0 1 0 9 0 7 ...
0 5 0 5 0 8 ...
0 9 0 1 0 2 ...
... 

i.e. in both files every alternate columns are zero. I want to merge them and form like this:

2 1 2 9 1 7...
3 5 9 5 2 8...
1 9 6 1 7 2...
...

and save this as a new mat file, 'file_3.mat'. And write this new file as an Image. How to do it?

Upvotes: 0

Views: 242

Answers (1)

m.s.
m.s.

Reputation: 16354

Assuming that A contains the first matrix and B contains the second, you just need to do:

C = A + B

Example:

% create dummy values
A = magic(5);
A(:,1:2:5) = 0;

B = magic(5);
B(:,2:2:5) = 0;

C = A + B

This will output:

C =

17    24     1     8    15
23     5     7    14    16
 4     6    13    20    22
10    12    19    21     3
11    18    25     2     9

Upvotes: 1

Related Questions