Google Группы больше не поддерживают новые публикации и подписки в сети Usenet. Опубликованный ранее контент останется доступен.

subtracting vector from each column of a matrix

4 472 просмотра
Перейти к первому непрочитанному сообщению

Sarmad

не прочитано,
27 янв. 2006 г., 12:01:4927.01.2006
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

не прочитано,
27 янв. 2006 г., 12:14:5827.01.2006

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

не прочитано,
27 янв. 2006 г., 12:33:1327.01.2006

"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

не прочитано,
27 янв. 2006 г., 12:47:3427.01.2006

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

/PB

Sarmad

не прочитано,
27 янв. 2006 г., 16:35:2327.01.2006

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

0 новых сообщений