Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

subtracting vector from each column of a matrix

4,472 views
Skip to first unread message

Sarmad

unread,
Jan 27, 2006, 12:01:49 PM1/27/06
to
How do you subtract a vector from each column of a matrix without
using a for loop? for example
1 2 3
4 5 6
7 8 9

and the vector is [1 2 3]' the result should then be
0 1 2
2 3 4
4 5 6

PB

unread,
Jan 27, 2006, 12:14:58 PM1/27/06
to

Try:
a=[1 2 3;4 5 6; 7 8 9]
b=[1 2 3]'

a-repmat(b,1,3)

see help repmat for more info.

/PB

joa

unread,
Jan 27, 2006, 12:33:13 PM1/27/06
to

"PB" <pbodin@_REMOVE_THiS_kth.se> wrote in message
news:ef26...@webx.raydaftYaTP...


Is anyone else getting the impression that someone gave this as a homework
excercise?


PB

unread,
Jan 27, 2006, 12:47:34 PM1/27/06
to

Yes, it struck my mind, right after my posting of a solution.

/PB

Sarmad

unread,
Jan 27, 2006, 4:35:23 PM1/27/06
to

Thank you all for the concearns but this isn't homework =)

0 new messages