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: Jonathan Webster
Subject: Re: Applying each element of a vector to each row of a matrix
Date: Sun, 19 Dec 2010 15:59:37 -0500
User-agent: Thunderbird 2.0.0.24 (X11/20101213)

Olaf Till wrote:
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).

_____________________
Having done a long stint at work using APL, and wanting to save my time rather than the computer's time, I long ago wrote rho.m , implementing the arbitrary reshape properties of the APL operator of that name. I can supply it if anyone is interested.
Here is an example:
octave:1> vv = [1 0 0 0 0]
vv =

  1   0   0   0   0

octave:2> u = rho( vv,4,4)
u =

  1   0   0   0
  0   1   0   0
  0   0   1   0
  0   0   0   1

Jonathan



_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave




reply via email to

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