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



i may have misunderstood, but it seems you only want to loop
through once.

if you remove the outer loop and replace references to n, by
m, you get the answer you wanted

a = [2 4 20 3 6];
b= [1 .9 .5 0 1]; 
    for m=1:length(b);
        if b(m) == 0
            b(m) = 1/(2.*a(m));
        elseif b(m) == 1
            b(m) = 1-(1/(2.*a(m)));
        else
            b(m) = b(m);
        end
    end
b =

    0.7500    0.9000    0.5000    0.1667    0.9167

regards,
david


"N N" <cvlm_2005@hotmail.com> wrote in message
<fushqi$j4c$1@fred.mathworks.com>...
> 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.
>