<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240226</link>
    <title>MATLAB Central Newsreader - looking for an index and value in array</title>
    <description>Feed for thread: looking for an index and value in array</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 01 Dec 2008 16:11:02 -0500</pubDate>
      <title>looking for an index and value in array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240226#614205</link>
      <author>muzaffar </author>
      <description>Dear All,&lt;br&gt;
if c=[1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1]&lt;br&gt;
how i can count no.of 1's between zeros. So i need to calculate numbers of 1's before a value zero and index of last 1 just before zero.&lt;br&gt;
thanks&lt;br&gt;
regards</description>
    </item>
    <item>
      <pubDate>Mon, 01 Dec 2008 17:13:13 -0500</pubDate>
      <title>Re: looking for an index and value in array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240226#614219</link>
      <author>Walter Roberson</author>
      <description>muzaffar wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; if c=[1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1]&lt;br&gt;
&amp;gt; how i can count no.of 1's between zeros. So i need to calculate numbers of 1's before&lt;br&gt;
&amp;gt; a value zero and index of last 1 just before zero.&lt;br&gt;
&lt;br&gt;
It isn't clear if you need this only for the first case, or repeatedly within the vector.&lt;br&gt;
If you only need the first, then:&lt;br&gt;
&lt;br&gt;
find(~c,1)-1&lt;br&gt;
&lt;br&gt;
Note: if the array begins with a 0, then this will report that there were zero 1's before&lt;br&gt;
the zero, which would be correct but perhaps not what you would want...&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
.signature note: I am now avoiding replying to unclear or ambiguous postings.&lt;br&gt;
Please review questions before posting them. Be specific. Use examples of what you mean,&lt;br&gt;
of what you don't mean. Specify boundary conditions, and data classes and value&lt;br&gt;
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?</description>
    </item>
    <item>
      <pubDate>Tue, 02 Dec 2008 06:10:20 -0500</pubDate>
      <title>Re: looking for an index and value in array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240226#614369</link>
      <author>Roger Stafford</author>
      <description>&quot;muzaffar&quot; &amp;lt;muzaffarbashir@yahoo.com&amp;gt; wrote in message &amp;lt;gh12am$kqi$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Dear All,&lt;br&gt;
&amp;gt; if c=[1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1]&lt;br&gt;
&amp;gt; how i can count no.of 1's between zeros. So i need to calculate numbers of 1's before a value zero and index of last 1 just before zero.&lt;br&gt;
&amp;gt; thanks&lt;br&gt;
&amp;gt; regards&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;I assume from your description that in your example you want a set of counts of 1, 7, and 2 for the three groups of 1's surrounded by 0's and indices 11, 21, and 28 for the 1's which were last in each such group of 1's.  In other words, the initial eight 1's and the final six 1's are not to be counted since they are not surrounded at both ends by 0's?  Is that correct?  If so, you can compute them this way:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;t = diff([1,c,1]);&lt;br&gt;
&amp;nbsp;cnt = find(t==1); cnt = cnt(1:end-1);&lt;br&gt;
&amp;nbsp;ind = find(t==-1); ind = ind(2:end)-1;&lt;br&gt;
&amp;nbsp;cnt = ind-cnt+1;&lt;br&gt;
&lt;br&gt;
The counts and indices are given by arrays 'cnt' and 'ind', respectively.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>

