Re: sorting and sum vector



"Par Hjalmarsson" <par.hjalmarsson@xxxxxxxxx> wrote in
message <fsqh99$mh3$1@xxxxxxxxxxxxxxxxxx>...
"Yi Cao" <y.cao@xxxxxxxxxxxxxxx> wrote in message <fsqgf2
$mur$1@xxxxxxxxxxxxxxxxxx>...
"Par Hjalmarsson" <par.hjalmarsson@xxxxxxxxx> wrote in
message <fsqfiu$4dc$1@xxxxxxxxxxxxxxxxxx>...
Hi,
I have a sorting and sum problem that I need to speed
up.
Hopefully there might be someone here that could help
me
do
this.

The code:

x=length(output2); %output2 is a Nx6 Matrix where N
is
a
value between 900000 and 5000000

xx=fix(((sqrt(output2(:,3).*output2(:,3)+output2
(:,4).*output2(:,4))/0.005))/mus)+1;

new_out=zeros(5000,1);

for j=1:x

new_out(xx(j))=new_out(xx(j))+output2(j,1)*exp(-
mua*
(output2(j,2)-output2(j,64))/mus);

end

Both mua and mus are constants.

/Par

You said output2 is Nx6, but you used output2(j,64)
here.
It is not correct.

Yi

Sorry should be output2(j,6)

Par

You may wish to use accumarray to replace your loop.
Something like (I have not tested it)

new_out=accumarray(xx,output2(:,1).*exp(-mua*(output2(:,2)-
output2(:,6))/mus));

hth.
Yi

.



Relevant Pages

  • Re: sorting and sum vector
    ... I have a sorting and sum problem that I need to ... Both mua and mus are constants. ...
    (comp.soft-sys.matlab)
  • Re: sorting and sum vector
    ... I have a sorting and sum problem that I need to speed ... Both mua and mus are constants. ...
    (comp.soft-sys.matlab)
  • Re: sorting and sum vector
    ... I have a sorting and sum problem that I need to speed up. ... Both mua and mus are constants. ...
    (comp.soft-sys.matlab)
  • sorting and sum vector
    ... I have a sorting and sum problem that I need to speed up. ... Both mua and mus are constants. ...
    (comp.soft-sys.matlab)