Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: simple calculation - where am I wrong?
Date: Fri, 25 Apr 2008 12:12:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <fushqi$j4c$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1209125522 19596 172.30.248.35 (25 Apr 2008 12:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 25 Apr 2008 12:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1265323
Xref: news.mathworks.com comp.soft-sys.matlab:465161



Could anyone help with the following calculation plse? 


a = [2 4 20 3 6]; 
%number of attempts at each level, total 5 levels; for 
example, first level was attempted 2 times

b= [1 .9 .5 0 1]; 
% percent correct at each level; for example, first level 
was correct 100 percent times 
 
for n=1:length(a);
    for m=1:length(b);
        if b(m) == 0
            b(m) = 1/(2.*a(n));
        elseif b(m) == 1
            b(m) = 1-(1/(2.*a(n)));
        else
            b(m) = b(m);
        end
    end
end
b

My aim is to get "b" without any 1s and 0s. Replaced 
numbers totally depend on number of attempts (higher the 
number of attempts, closer the "b" will be to "one" 
or "zero".

With the above code, all the replaced numbers have been 
calculated based on 1st element of &#8220;a&#8221; (think my code is 
incorrect somewhere) 

Current answer is the following:
b =
    0.75    0.90    0.50    0.25    0.75 
(In this answer, last 2 calculations are incorrect)

Expected answer:
b =
    0.75    0.90    0.50    0.17    0.92

Help is much appreciated. Thanks.