Thread Subject: row wise subtraction

Subject: row wise subtraction

From: Camron Call

Date: 25 Nov, 2009 22:35:20

Message: 1 of 2

I am trying to see if there is a way to subtract a 1x92 vector from each row of a 1000x92 vector without a for loop.

for example: I want to subtract row 1 from all the rows.

     1 1 1 1 1
     2 2 2 2 2
     3 3 3 3 3
     4 4 4 4 4
     5 5 5 5 5

to take the above matrix to

     0 0 0 0 0
     1 1 1 1 1
     2 2 2 2 2
     3 3 3 3 3
     4 4 4 4 4

shouldn't be that tough right?

Subject: row wise subtraction

From: Jonas

Date: 25 Nov, 2009 23:03:19

Message: 2 of 2

"Camron Call" <camroncall@gmail.cam> wrote in message <hekbf8$5n6$1@fred.mathworks.com>...
> I am trying to see if there is a way to subtract a 1x92 vector from each row of a 1000x92 vector without a for loop.
>
> for example: I want to subtract row 1 from all the rows.
>
> 1 1 1 1 1
> 2 2 2 2 2
> 3 3 3 3 3
> 4 4 4 4 4
> 5 5 5 5 5
>
> to take the above matrix to
>
> 0 0 0 0 0
> 1 1 1 1 1
> 2 2 2 2 2
> 3 3 3 3 3
> 4 4 4 4 4
>
> shouldn't be that tough right?

Have a look at bsxfun

A = [1 1 1 1 1
      2 2 2 2 2
      3 3 3 3 3
      4 4 4 4 4
      5 5 5 5 5 ];

B = bsxfun(@minus,A,A(1,:));

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com