Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

subtracting vector from each column of a matrix

4.472 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Sarmad

ungelesen,
27.01.2006, 12:01:4927.01.06
an
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

ungelesen,
27.01.2006, 12:14:5827.01.06
an

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

ungelesen,
27.01.2006, 12:33:1327.01.06
an

"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

ungelesen,
27.01.2006, 12:47:3427.01.06
an

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

/PB

Sarmad

ungelesen,
27.01.2006, 16:35:2327.01.06
an

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

0 neue Nachrichten