Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave operator -: automatic broadcasting operation applied

In octave 3.6.2, I have a matrix X=[1 2 3; 2 4 5; 2 6 5; 2 3 7; 3 6 8; 2 4 6; 3 6 8; 4 7 10] and I want to calculate X-mean(X), which gives me:

octave:2> X-mean(X)
warning: operator -: automatic broadcasting operation applied
ans =

  -1.37500  -2.75000  -3.50000
  -0.37500  -0.75000  -1.50000
  -0.37500   1.25000  -1.50000
  -0.37500  -1.75000   0.50000
   0.62500   1.25000   1.50000
  -0.37500  -0.75000  -0.50000
   0.62500   1.25000   1.50000
   1.62500   2.25000   3.50000

however, when I try the same command on a different machine, it complains that the sizes of matrices do not match:

error: operator -: nonconformant arguments (op1 is 7x3, op2 is 1x3)

Any idea how to activate that "automatic broadcasting operation" which is applied in the first case? (octave versions are the same!)

like image 733
Vahid Mirjalili Avatar asked Jun 13 '13 18:06

Vahid Mirjalili


1 Answers

You can explicitly request broadcasting by calling bsxfun(operation, A, B), so in your case:

bsxfun(@minus, X, mean(X))

Octave reference, Matlab reference

like image 116
emu Avatar answered Sep 19 '22 07:09

emu