Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: solving logic , array and condition, matrix
Date: Wed, 30 May 2012 00:37:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 46
Message-ID: <jq3q3l$ato$1@newscl01ah.mathworks.com>
References: <f44f3b2a-9bd4-4afb-8165-c7fc56932ecd@cu1g2000vbb.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1338338229 11192 172.30.248.38 (30 May 2012 00:37:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 30 May 2012 00:37:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:769391

Markov Paris <markov.matlab@gmail.com> wrote in message <f44f3b2a-9bd4-4afb-8165-c7fc56932ecd@cu1g2000vbb.googlegroups.com>...
> stateHit = zeros(length(stateCount),6);
>   for n = 1:length(stateCount)
>  if (stateCount(n)<= 5)
>         stateHit(n,1) = 1;
>  else
>  if (stateCount(n)> 5 &&  stateCount(n)<= 10)
>             stateHit(n,2) = 1;
> else
> if (stateCount(n)>10 &&  stateCount(n)<= 15)
>         stateHit(n,3) = 1;
> else
> if (stateCount(n)> 15 &&  stateCount(n)<= 20)
>         stateHit(n,4) = 1;
> else
>  if (stateCount(n)> 20 && stateCount(n)<= 25)
>     stateHit(n,5) = 1;
> else
> if (stateCount(n)> 25 &&  stateCount(n)<= 30)
>     stateHit(n,6) = 1;
> end
> end
> end
> end
>  end
>  end
>  end
- - - - - - - - - -
  There are other ways of solving your problem that don't require for-loops.  However I'll stick with your for-loops for the purpose of this discussion.  You do need a different p.  Let p be defined as:

 p = [-inf,5,10,15,20,25,30];

Let v be short for 'value' and h be short for 'stateHit'.

 h = zeros(length(v),length(p)-1);
 for n = 1:length(v)
   for k = 1:length(p)-1
     if p(k) < v(n) & v(n) <= p(k+1)
       h(n,k) = 1;
     end
   end
 end

  It is possible to "vectorize" this using the 'histc' function and with a more general p in case you become adventuresome and want to explore other possibilities.

Roger Stafford