comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Can this be vectorized?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Can this be vectorized? [message #17455 is a reply to message #17445] Tue, 26 October 1999 00:00 Go to previous messageGo to previous message
Gautam Sethi is currently offline  Gautam Sethi
Messages: 2
Registered: October 1999
Junior Member
In comp.soft-sys.matlab Bert Jagers <hrajagers@my-deja.com> wrote:
: Dear John,

: Two solutions in Matlab: one completely vectorized, one partially.
: Of course, you could also implement it as a MEX file.

: F=find([1 diff(I) 1]);
: XS=[0 cumsum(X)];
: Y=XS(F(2:end))-XS(F(1:(end-1)));

: There is one major drawback to this implementation, since

:> In reality, X consists of about one million elements,

: you may loose accuracy when taking the difference of two large
: cummulative values. So, I tried to find another solution.

: F=find([1 diff(I) 1]);
: Y=zeros(1,length(F)-1);
: for i=1:length(Y),
: Y(i)=sum(X(F(i):(F(i+1)-1)));
: end;

: The memory usage is probably comparable. In both cases there needs to
: be space for the matrices I,X,F and [1 diff(I) 1], or else Matlab will
: start swapping.

: Best regards,

: Bert Jagers

since memory is of issue, you may want to try this non-vectorized one as well:
------------------------------------------------------------ ------
function K = davis(I,J)

for i = min(I):max(I)
K(i) = sum(J(find(I == i)));
end
------------------------------------------------------------ ------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Object graphics axis
Next Topic: 'ffff'x is negative in 5.2 positive in 5.2.1

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:34:42 PDT 2025

Total time taken to generate the page: 0.00410 seconds