From: "Elnaz " <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Can this run any faster?
Date: Wed, 10 Apr 2013 19:29:05 +0000 (UTC)
Organization: Georgia Institute of Technology
Lines: 26
Message-ID: <kk4ei1$6ku$>
References: <kk24q4$3j5$> <kk2qqh$158$>
Reply-To: "Elnaz " <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1365622145 6814 (10 Apr 2013 19:29:05 GMT)
NNTP-Posting-Date: Wed, 10 Apr 2013 19:29:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 998620
Xref: comp.soft-sys.matlab:793202

Thanks Roger; that is a clever substitute. It runs 0.01 second faster than the original one. 

The code above is an excerpt of BCJR algorithm. It is the forward recursion part which sweeps over the trellis structure from the beginning to the end in forward direction. 
It is difficult to explain in words what that excerpt is trying to do for the general audience since it requires a lot of backgroun math to set the scene. 

I have another loop similar to the first one which is a backward recursion. It starts from the end working its way to the beginning:

% Backwards recursion 
    for i= length-1:-1:1
       for j= 1:32
           A = b(transitions(j,1),i);
           B = b(transitions(j,2),i+1) + ug (j, i+1) + eg(j, i+1);
           if(A == -inf && B == -inf)
              b(transitions(j,1),i) = -inf;
              b(transitions(j,1),i)= max(A,B) + log(1+exp(-abs(A-B)));  

If I apply Roger's idea I get 0.02 sec improvement in one calling. However, the main problem that costs time here is the big length of the signal (the variable i here). 
But thanks Roger, that was clever.