Reputation: 1121
I have two matrices to be subtracted. Let's see the code below.
A=rand(5472,1);
B=rand(1,3);
C= bsxfun(@minus, A, B(:))
I get the error saying that
Non-singleton dimensions of the two input arrays must match each other
Any idea why this error? Thanks!
Upvotes: 0
Views: 156
Reputation: 4195
you are trying to apply bsxfun
on two column vectors, while you should apply it on one row and one column vector.
bsxfun
inputs should have different singelton dimensions (size(arr,dim) == 1
). in your example size(A) = [5472,1]
and size(B) = [1,3]
which is appropriate input (A
's singelton dimension is 2 and B
's singelton dimension is 1), but when you do B(:)
- B
's singelton dimension becomes 2, like A
's, which throws an error.
do:
A=rand(5472,1);
B=rand(1,3);
C= bsxfun(@minus, A, B)
Upvotes: 4