Search All of the Math Forum:

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

Topic: Subtract values in a matrix
Replies: 6   Last Post: Nov 19, 2012 12:20 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 17,998 Registered: 12/7/04
Re: Subtract values in a matrix
Posted: Nov 19, 2012 12:20 AM

"Bob Ferreira" <migmick2000@hotmail.com> wrote in message
news:k88nie\$f7r\$1@newscl01ah.mathworks.com...
> Hi there!
>
> I need really need some help on this,
> I have a matrix which has "L" lines and "C" columns. I want to subtract
> each value in the matrix by the value the first value in the first line of
> its column, and give me a matrix with those value, with the first values
> of the first line being "0".
>
> Example: m = [2,2,2;3,3,3;4,4,4] the matrix given should be
> [0,0,0;-1,-1,-1;-2,-2,-2]
>
>
> Thank you for your time.

m = [2,2,2;3,3,3;4,4,4];
m2 = bsxfun(@minus, m(1, :), m)

--
Steve Lord
slord@mathworks.com
http://www.mathworks.com

Date Subject Author
11/17/12 Bob Ferreira
11/17/12 dpb
11/17/12 Bob Ferreira
11/17/12 dpb
11/17/12 Daniel Gebhardt
11/17/12 Bob Ferreira
11/19/12 Steven Lord