Vahid Mirjalili
Vahid Mirjalili

Reputation: 6501

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!)

Upvotes: 12

Views: 13239

Answers (2)

user3836580
user3836580

Reputation: 61

sorry to come in so late. Although with the same version, you are likely to have the 2nd machine setup different.

Look at Octave Broadcasting documentation, you can set the warning beahaviour directly:

warning ("error", "Octave:broadcast");

vs.

warning ("off", "Octave:broadcast");

Upvotes: 6

emu
emu

Reputation: 1673

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

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

Octave reference, Matlab reference

Upvotes: 19

Related Questions