Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



how apply bsxfun to all the rows of a matrix?
Posted:
Dec 27, 2011 5:39 PM


hello everybody
let me ask my question though the following example:
test=[1 1 1 1; 2 2 2 2; 3 3 3 3;4 4 4 4]
test = 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
rowDiff=bsxfun(@minus, test, test(1,:)) % for the first row of test
rowDiff = 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3
sum(rowDiff.^2,2)'
ans = 0 4 16 36
How could I repeat the above for all the rows of test, without any loop in the code?
At last, please let me express my appreciation to the people in this great google group, and my special thanks to Bruno Luong and and Matt J for their invaluable comments and solutions to my previous questions. Aseman



