Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: how apply bsxfun to all the rows of a matrix?
Replies: 2   Last Post: Dec 27, 2011 7:00 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
andalibar@gmail.com

Posts: 17
Registered: 2/28/07
how apply bsxfun to all the rows of a matrix?
Posted: Dec 27, 2011 5:39 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.