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 #17456 is a reply to message #17445] Tue, 26 October 1999 00:00 Go to previous message
Bert Jagers is currently offline  Bert Jagers
Messages: 1
Registered: October 1999
Junior Member
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


Sent via Deja.com http://www.deja.com/
Before you buy.
[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:25:29 PDT 2025

Total time taken to generate the page: 0.00390 seconds