1

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.

4

3 回答 3

3

在 Maltab 中(它也可以在 Octave 中工作),您可以使用二进制单例展开

bsxfun(@minus, a, mu)

但是,我的理解是 Octave 会自动为您广播,因此尝试从 2x2 中减去 1x2 矩阵时不会出错...:/

于 2013-05-03T21:47:29.460 回答
1

normalized = a - repmat(mu, size(a,1), 1)

于 2013-05-03T21:49:24.183 回答
1
normalized  = [a(:,1) - mu(1), a(:,2) - mu(2)];
于 2013-05-03T21:34:23.733 回答