help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vector approach to row margin frequencies


From: Jaroslav Hajek
Subject: Re: Vector approach to row margin frequencies
Date: Wed, 24 Jun 2009 06:40:55 +0200

On Wed, Jun 24, 2009 at 12:39 AM, ws<address@hidden> wrote:
> In an attempt to learn more about octave, I am trying to figure out how to
> calculate the row frequencies for the following matrix (call it X):
>
> 3,560   5,421   15,983
> 4,768   9,777   8,033
> 4,960   5,251   8,390
> 5,518   5,205   3,402
> 7,847   21,538  83,351
> 3,376   6,026   9,606
> 11,704  19,316  50,241
> 4,644   4,967   6,607
> 12,171  26,274  134,419
> 2,689   6,069   15,849
> 18,010  29,712  100,240
> 4,121   5,287   11,214
> 5,968   12,433  149,215
> 1,870   2,773   18,760
> 5,562   12,213  109,476
> 1,109   2,977   10,452
>
> I am able to get the row totals with S=sum(X,2):
>
>    24964
>    22578
>    18601
>    14125
>   112736
>    19008
>    81261
>    16218
>   172864
>    24607
>   147962
>    20622
>   167616
>    23403
>   127251
>    14538
>
> I would love to now get the row frequencies avoiding a while loop, something
> like F=X./S, but that doesn't work (though it seems somehow consistent -- I
> realize that we don't recycle vectors in Octave/ Mat* ) ....
>
> Perhaps there is something like an "apply" command?
>
> I can do this in a while loop if I have to, but I don't want to...
>
> Tx!
>
>

In 3.2.0, the fastest way is also the most obvious (from math point of view):

F = X / diag (S)

In 3.0.x, take any of the bsxfun or repmat workarounds (or just use
the above and upgrade to 3.2 soon)

cheers

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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