What should be the size of the matrices to use elemental separation?

res = A ./ B

I tried,

res = [1 2] ./ [1 2]
res = [1 2] ./ [1 2; 2 3] 
res = [1 2] ./ [1 2; 2 3; 3 4]
res = [1 2; 2 3] ./ [1 2; 2 3] 

They all work.

But it doesn’t work

res = [1 2; 2 3] ./ [1 2; 2 3; 3 4] 

So what is the rule for dimensionality really?

+4
source share
1 answer

This is some confusion that has emerged thanks to the new MATLAB automatic broadcast measurement .

First of all, note that the operator ./is an elementary operation.

In MATLAB versions prior to R2016b, using this operator will require the two inputs to be exactly the same.

[1 2] ./ rand(4)

Matrix sizes must match.

( ), bsxfun

bsxfun(@rdivide, [1 2], [1 2; 2 3]);

, .

.

, 1 2. 2 2, .

R2016b MATLAB , , bsxfun, .

,

[1 2; 2 3] ./ [1 2; 2 3; 3 4]

[2 x 2], - [3 x 2]. , .

+5

Source: https://habr.com/ru/post/1663648/


All Articles