matlab - repmat function does not work properly -
let consider following situation,for instance have given matrix , want make 0 centered matrix in columns,so
a=rand(4,3) = 0.6948 0.4387 0.1869 0.3171 0.3816 0.4898 0.9502 0.7655 0.4456 0.0344 0.7952 0.6463
now 2 method works properly
a-repmat(mean(a),size(a,1),1) ans = 0.1957 -0.1565 -0.2553 -0.1820 -0.2137 0.0476 0.4511 0.1703 0.0035 -0.4647 0.1999 0.2042
and also
bsxfun(@minus,a,mean(a)) ans = 0.1957 -0.1565 -0.2553 -0.1820 -0.2137 0.0476 0.4511 0.1703 0.0035 -0.4647 0.1999 0.2042
but somehow following method not work
b=mean(a) b = 0.4991 0.5953 0.4421 a-repmat(b,1,4) ans = 0 0 0 0 0 0 0 0 0 0 0 0
i have tried transpose but
a-repmat(b,1,4)' error using - matrix dimensions must agree.
also have tried following
a-repmat(b,1,3)' error using - matrix dimensions must agree. >> a-repmat(b,1,3) error using - matrix dimensions must agree. problem of failure of method?
you not using proper syntax repmat function
in example ,you need create matrix of size 4 x 3
using repmat
now call repmat(a,k,j)
repeats matrix a
k
times along first dimension (i.e vertically) , j
times along second dimension (i.e, horizontally).
here, need repeat matrix mean
4 times in first dimension , 1 time in second dimension .
hence, correct call repmat repmat(mean,4,1)
repmat(b,4,1) ans = 0.4991 0.5953 0.4421 0.4991 0.5953 0.4421 0.4991 0.5953 0.4421 0.4991 0.5953 0.4421
it looks need know why method failing
repmat(b,1,4) %// returns 1x12 matrix while 3x4 matrix hence dimensions not agree while using @minus ans = 0.4991 0.5953 0.4421 0.4991 0.5953 0.4421 0.4991 0.5953 0.4421 0.4991 0.5953 0.4421
Comments
Post a Comment