<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Creating a counter in matlab.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Creating a counter in matlab.' posted on the 'Matlab' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sun, 19 May 2013 04:41:46 -0700</pubDate>
    <lastBuildDate>Sun, 19 May 2013 04:41:46 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Creating a counter in matlab.</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427438/creating-a-counter-in-matlab/</link>
      <description>Hello. what im trying to do is create a random walk simulation 1000 times where i am tracking the movement of an object in 48 steps. i figured out what i need to do, but the last thing im trying to do is to count how many times the walk ends at a number where y&amp;gt;12. So for example if the walk ends at y=13, it adds 1 to the counter, but if it ends on y=8, it will not add 1 to the counter.&lt;br /&gt;
The reason im doing this is so i can find a percentage of how many times the object ends at y&amp;gt;12 which i want to do by finding 'number of times object went over twelve divided by 1000&lt;br /&gt;
(ans=counter/1000). heres my code:&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; %n= # of fungus sources&lt;br /&gt;
&amp;gt;&amp;gt; %t= # of time steps (inch)&lt;br /&gt;
&amp;gt;&amp;gt; %N= # of simulation runs&lt;br /&gt;
&amp;gt;&amp;gt; %alfa= random variables for angle&lt;br /&gt;
&amp;gt;&amp;gt; %d= random variable for distance&lt;br /&gt;
&amp;gt;&amp;gt; %M1= x coordinate of a point&lt;br /&gt;
&amp;gt;&amp;gt; %M2= y coordinate at a point&lt;br /&gt;
&amp;gt;&amp;gt; %maxy= max y value at each step&lt;br /&gt;
&amp;gt;&amp;gt; %count= counter that stores # of times maxy is &amp;gt; 12 inches&lt;br /&gt;
&amp;gt;&amp;gt; n=1; &lt;br /&gt;
&amp;gt;&amp;gt; t=48;&lt;br /&gt;
&amp;gt;&amp;gt; N=1000;&lt;br /&gt;
&amp;gt;&amp;gt; count=0;&lt;br /&gt;
&amp;gt;&amp;gt; for n=1:N;&lt;br /&gt;
m1(1,1:n)=1:n;&lt;br /&gt;
m2(1,1:n)=(1:n)*0;&lt;br /&gt;
maxy=0;&lt;br /&gt;
for i=1:t;&lt;br /&gt;
alfa=rand(1,n)*pi;&lt;br /&gt;
d=randn(1,n);&lt;br /&gt;
m1(i+1,1:n)=m1(i,1:n)+(d.*cos(alfa));&lt;br /&gt;
m2(i+1,1:n)=m2(i,1:n)+(d.*sin(alfa));&lt;br /&gt;
if m2(i+1,1:n)&amp;lt;0;&lt;br /&gt;
m2(i+1,1:n)=-m2(i+1,1:n);&lt;br /&gt;
end;&lt;br /&gt;
end;&lt;br /&gt;
maxy=max(maxy,m2(i+1,1:n));&lt;br /&gt;
&lt;br /&gt;
end;&lt;br /&gt;
&amp;gt;&amp;gt; if maxy&amp;gt;12&lt;br /&gt;
count=count+1&lt;br /&gt;
end;&lt;br /&gt;
&amp;gt;&amp;gt; ans=count/N&lt;br /&gt;
&lt;br /&gt;
ans =&lt;br /&gt;
&lt;br /&gt;
     0&lt;br /&gt;
....&lt;br /&gt;
Looking at my workspace i see there are times when y&amp;gt;12 but my counter is not recording it, so i keep getting an answer of 0.  Any suggestions on how to get my counter working? Much appreciated.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427438/creating-a-counter-in-matlab/</guid>
      <pubDate>Wed, 15 Feb 2012 20:21:01 -0700</pubDate>
      <category>Matlab</category>
    </item>
    <item>
      <title>Re: Creating a counter in matlab.</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427443/re-creating-a-counter-in-matlab/#427443</link>
      <description>You have to index maxy, something like this:&lt;br /&gt;
maxy(n)=max(maxy(n-1),m2(i+1,1:n));&lt;br /&gt;
then out of the for loop&lt;br /&gt;
pos=find(maxy&amp;gt;12)&lt;br /&gt;
finds the positions of the elements &amp;gt;12&lt;br /&gt;
then&lt;br /&gt;
values=maxy(pos)&lt;br /&gt;
finds the values of the elements &amp;gt;12&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427443/re-creating-a-counter-in-matlab/#427443</guid>
      <pubDate>Thu, 16 Feb 2012 00:40:12 -0700</pubDate>
      <category>Matlab</category>
    </item>
    <item>
      <title>Re: Creating a counter in matlab.</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427452/re-creating-a-counter-in-matlab/#427452</link>
      <description>as soon as i replace the line to 'maxy(n)=max(maxy(n-1),m2(i+1,1:n))' it gives me this error:'??? Attempted to access maxy(0); index&lt;br /&gt;
must be a positive integer or logical.'&lt;br /&gt;
'&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427452/re-creating-a-counter-in-matlab/#427452</guid>
      <pubDate>Thu, 16 Feb 2012 07:47:20 -0700</pubDate>
      <category>Matlab</category>
    </item>
    <item>
      <title>Re: Creating a counter in matlab.</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427466/re-creating-a-counter-in-matlab/#427466</link>
      <description>Yes, you have to shift the indices. Because when n=1, n-1=0 and maxy(0) doesn't exist.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/427438/427466/re-creating-a-counter-in-matlab/#427466</guid>
      <pubDate>Thu, 16 Feb 2012 23:52:38 -0700</pubDate>
      <category>Matlab</category>
    </item>
  </channel>
</rss>