help-octave
[Top][All Lists]
Advanced

[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: Olaf Till
Subject: Re: Applying each element of a vector to each row of a matrix
Date: Sun, 19 Dec 2010 21:09:37 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

On Sun, Dec 19, 2010 at 12:42:23PM -0600, Jordi Gutiérrez Hermoso wrote:
> 2010/12/19 Martin Helm <address@hidden>:
> > Am Sonntag, 19. Dezember 2010, 18:08:45 schrieb Jordi Gutiérrez Hermoso:
> 
> >> No, no... exponentiate each row or column of a matrix by each element
> >> of a vector.
> >
> > Ah - I see, sorry misunderstood completely. I have no good solution for 
> > that I
> > think repmat is the best solution or something similar to that
> 
> Okay, so does my original proposal to extend elementwise operators for
> the matrix-vector case of compatible dimensions sound silly? I am just
> wondering why no one else seems to have wanted such an extension so
> far, so perhaps I'm overlooking something blindingly obvious.

Well, there is something one already can use, though maybe with too
much overhead:

octave:4> cat (2, cellfun (@ (x) x .^ ones (4, 1), num2cell (ones (4, 3), 1), 
"UniformOutput", false){:})
ans =

   1   1   1
   1   1   1
   1   1   1
   1   1   1

octave:5> 

This example exponenciates each column of ones(4, 3) with the vector
ones(4, 1).

Olaf


reply via email to

[Prev in Thread] Current Thread [Next in Thread]