matlab - How to multiply matrix having different size (without knowing exactly the size they will have)? -


i have multiply 2 matrices (scalar multiplication) have different sizes. instance, 1st has size n-by-m , 2nd n+1-by-m+1. fact is not case. mean, first has size n+1-by-m+1 , 2nd n-by-m or n+2-by-m+2 etc...

example:

a = [ 1 2 3;        4 5 6];   b = [ 1 2 3;        4 5 6;        7 8 9] 

i matlab check size of each matrix, multiply them using smallest size available between 2 i.e. ignoring last rows , columns of bigger matrix (or similarly, adding rows , columns of 0 smaller matrix).

with example inputs obtain:

c = [1  4  9;       16 25 36]  

or

c = [1  4  9;       16 25 36;       0  0  0] 

how can write this?

find number of rows , columns of final matrix:

n = min(size(a,1), size(b,1)); m = min(size(a,1), size(b,1)); 

then extract relevant sections of a , b (using : operator) multiplication:

c = a(1:n,1:m).*b(1:n,1:m) 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -