[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Applying each element of a vector to each row of a matrix
From: |
Martin Helm |
Subject: |
Re: Applying each element of a vector to each row of a matrix |
Date: |
Sun, 19 Dec 2010 17:03:50 +0100 |
User-agent: |
KMail/1.13.5 (Linux/2.6.34.7-0.5-desktop; KDE/4.5.4; x86_64; ; ) |
Am Sonntag, 19. Dezember 2010, 16:33:20 schrieb Jordi Gutiérrez Hermoso:
> I'm often found with a situation in which I have some matrix A and
> some vector v and I would like to do something like multiply each
> column or row in A by each element of v. I've wished that something
> like A.*v or v.*A would do this if the row or column dimensions of A
> matched those of v, but of course this doesn't work. I end up
> resorting to repmat instead to turn v into a matrix whose dimensions
> match those of A.
>
> My questions are, is there another way to do this more cleanly without
> first calling repmat? If there isn't, would this be a reasonable
> extension of the elementwise operators?
>
> Thanks in advance,
> - Jordi G. H.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
There is a special type "diagonal matrix" which should fit your needs.
with diag(v) you create a diagonal matrix which behaves like a matrix and can
be used to scale rows/columns without the overhead of creating a full matrix
(and a corresponding full matrix multiplication), but only in newer octave
versions, I do not remember when it was introduced.
diag(v)*a for example
- Applying each element of a vector to each row of a matrix, Jordi Gutiérrez Hermoso, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix,
Martin Helm <=
- Re: Applying each element of a vector to each row of a matrix, Jordi Gutiérrez Hermoso, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Martin Helm, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Jordi Gutiérrez Hermoso, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Martin Helm, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Jordi Gutiérrez Hermoso, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Olaf Till, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Jonathan Webster, 2010/12/19
- Re: Applying each element of a vector to each row of a matrix, Jordi Gutiérrez Hermoso, 2010/12/20
- Re: Applying each element of a vector to each row of a matrix, Jonathan Webster, 2010/12/20
- Re: Applying each element of a vector to each row of a matrix, Jordi Gutiérrez Hermoso, 2010/12/19