Reputation: 2640
I'm brand new to Octave, and I'm trying to do some basic matrix operations. I'll give a simple example of what I'm trying to do (actual data set is much larger).
a = [1 2; 2 4]
mu = mean(a)
normalized = a - mu %error line
So in my example, the mu values are 1.5 and 6. I'd like to get a matrix back that has 1.5 subtracted from the first column, and 3 subtracted from the 2nd.
Such as:
-.5 -1 .5 1
Big thanks in advance.
Upvotes: 1
Views: 553
Reputation: 45751
In Maltab (and it will work in Octave too) you would do it using a binary singelton expansion:
bsxfun(@minus, a, mu)
However, my understanding is that Octave does broadcasting automatically for you and so you shouldn't get an error trying to subtract a 1x2 matrix from a 2x2... :/
Upvotes: 3