# Hi every one is there any way how to subtradt two matrices of different dimension let say A=<424x544x3uint8> and B=<462x545x3 uint8> How can we perform subtraction like S=A-B. Thanks

1 view (last 30 days)
sachin on 22 Oct 2014
Answered: Andy on 22 Oct 2014
the cyclist on 22 Oct 2014
Suppose
A = [1 2 3]
and
B = [4 5]
What do you mean by A - B?

Andy on 22 Oct 2014
How about expanding the two inputs to generate matrices with matching dimensions, assuming A(1,1) lines up with B(1,1)
Asize=size(A);
Bsize=size(B);
Csize=max(Asize,Bsize);
Anew=zeros(Csize);
Bnew=zeros(Csize);
Anew(1:Asize(1),1:Asize(1,2))=A;
Bnew(1:Bsize(1),1:Bsize(1,2))=B;
S=Anew-Bnew;
Alternatively trim them to the same size after finding the size of the overlap,
Asize=size(A);
Bsize=size(B);
Csize=min(Asize,Bsize);
Anew=A(1:Asize(1),1:Asize(1,2));
Bnew=B(1:Asize(1),1:Bsize(1,2));
S=Anew-Bnew;

### Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

### Tags

No tags entered yet.

### Community Treasure Hunt

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

Start Hunting!

Translated by