<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164646</link>
    <title>MATLAB Central Newsreader - error in while function</title>
    <description>Feed for thread: error in while function</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>Wed, 27 Feb 2008 06:19:29 -0500</pubDate>
      <title>error in while function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164646#417610</link>
      <author>sronggot</author>
      <description>Dear,&lt;br&gt;
&lt;br&gt;
I have problem with my matlab programming, i use while for my iteration and after i run my program.. there are message error like this &lt;br&gt;
&lt;br&gt;
'??? Attempted to access U1(:,1); index out of bounds because numel(U1)=1.'&lt;br&gt;
&lt;br&gt;
anyone can help me to solve this problem..&lt;br&gt;
&lt;br&gt;
this my simple program :&lt;br&gt;
&lt;br&gt;
&amp;nbsp;i=1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;U1(1)=500;%First guess [W/m2C]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while abs((U1(i+1)-U1(i))/U1(i+1))&amp;gt;=0.01&lt;br&gt;
A_total=Duty*1000/(U1(i)*delta_T)&lt;br&gt;
i=1+i;&lt;br&gt;
U1(i)=1/A_total;&lt;br&gt;
end&lt;br&gt;
U1final=U1(i)</description>
    </item>
    <item>
      <pubDate>Wed, 27 Feb 2008 06:35:47 -0500</pubDate>
      <title>Re: error in while function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164646#417614</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;6820854.1204093199469.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;,&lt;br&gt;
sronggot  &amp;lt;istardi@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;I have problem with my matlab programming, i use while for my iteration and after i run my program.. there are message error like this &lt;br&gt;
&lt;br&gt;
&amp;gt;'??? Attempted to access U1(:,1); index out of bounds because numel(U1)=1.'&lt;br&gt;
&lt;br&gt;
&amp;gt;anyone can help me to solve this problem..&lt;br&gt;
&lt;br&gt;
&amp;gt;this my simple program :&lt;br&gt;
&lt;br&gt;
&amp;gt; i=1;&lt;br&gt;
&amp;gt;        U1(1)=500;%First guess [W/m2C]&lt;br&gt;
&amp;gt;        while abs((U1(i+1)-U1(i))/U1(i+1))&amp;gt;=0.01&lt;br&gt;
&lt;br&gt;
i starts at 1, and U1 starts at only one element [U1(1)=500],&lt;br&gt;
and the very first access you make is to U1(i+1) which would be to&lt;br&gt;
U1(2) which does not exist.&lt;br&gt;
&lt;br&gt;
&amp;gt;A_total=Duty*1000/(U1(i)*delta_T)&lt;br&gt;
&amp;gt;i=1+i;&lt;br&gt;
&amp;gt;U1(i)=1/A_total;&lt;br&gt;
&amp;gt;end&lt;br&gt;
&amp;gt;U1final=U1(i)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
You will have to completely rethink your code; there is no obvious&lt;br&gt;
way to fix it that would not destroy the code structure you have&lt;br&gt;
established.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&quot;Is there any thing whereof it may be said, See, this is new? It hath&lt;br&gt;
&amp;nbsp;&amp;nbsp;been already of old time, which was before us.&quot;    -- Ecclesiastes</description>
    </item>
    <item>
      <pubDate>Wed, 27 Feb 2008 07:39:02 -0500</pubDate>
      <title>Re: error in while function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164646#417619</link>
      <author>Roger Stafford</author>
      <description>sronggot &amp;lt;istardi@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;6820854.1204093199469.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Dear,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have problem with my matlab programming, i use while for my iteration &lt;br&gt;
and after i run my program.. there are message error like this &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; '??? Attempted to access U1(:,1); index out of bounds because numel(U1)&lt;br&gt;
=1.'&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; anyone can help me to solve this problem..&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; this my simple program :&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  i=1;&lt;br&gt;
&amp;gt;         U1(1)=500;%First guess [W/m2C]&lt;br&gt;
&amp;gt;         while abs((U1(i+1)-U1(i))/U1(i+1))&amp;gt;=0.01&lt;br&gt;
&amp;gt; A_total=Duty*1000/(U1(i)*delta_T)&lt;br&gt;
&amp;gt; i=1+i;&lt;br&gt;
&amp;gt; U1(i)=1/A_total;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; U1final=U1(i)&lt;br&gt;
--------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Perhaps you should describe in words what you are trying to accomplish &lt;br&gt;
with your code.  The interior of the while-loop seems to be using elements of &lt;br&gt;
the U1 vector that haven't yet been defined.  But whether or not that is so, &lt;br&gt;
you appear to be multiplying each element in U1 by a fixed constant, delta_T/&lt;br&gt;
(Duty*1000), to obtain the value which is to replace the next element without &lt;br&gt;
regard to whatever value that element might have previously possessed.  This &lt;br&gt;
gives you a geometric series which continues until you encounter two &lt;br&gt;
successive values in U1 that differ by less than one percent.  As it stands, it &lt;br&gt;
does not seem to make a lot of sense, and we are left guessing what it is you &lt;br&gt;
really had in mind.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Wed, 27 Feb 2008 12:12:02 -0500</pubDate>
      <title>Re: error in while function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164646#417644</link>
      <author>Yi Cao</author>
      <description>sronggot &amp;lt;istardi@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;6820854.1204093199469.JavaMail.jakarta@nitrogen.mathforum.o&lt;br&gt;
rg&amp;gt;...&lt;br&gt;
&amp;gt; Dear,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have problem with my matlab programming, i use while &lt;br&gt;
for my iteration and after i run my program.. there are &lt;br&gt;
message error like this &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; '??? Attempted to access U1(:,1); index out of bounds &lt;br&gt;
because numel(U1)=1.'&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; anyone can help me to solve this problem..&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; this my simple program :&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  i=1;&lt;br&gt;
&amp;gt;         U1(1)=500;%First guess [W/m2C]&lt;br&gt;
&amp;gt;         while abs((U1(i+1)-U1(i))/U1(i+1))&amp;gt;=0.01&lt;br&gt;
&amp;gt; A_total=Duty*1000/(U1(i)*delta_T)&lt;br&gt;
&amp;gt; i=1+i;&lt;br&gt;
&amp;gt; U1(i)=1/A_total;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; U1final=U1(i)&lt;br&gt;
&lt;br&gt;
I guess the following code is what you want although it is &lt;br&gt;
not a good practice to dynamically expand U1:&lt;br&gt;
&lt;br&gt;
Duty=0.1; % just take a value for test&lt;br&gt;
delta_T=1;&lt;br&gt;
e=100; % initial error&lt;br&gt;
i=1;&lt;br&gt;
U1(1)=500;&lt;br&gt;
while e&amp;gt;=0.01&lt;br&gt;
A_total=Duty*1000/(U1(i)*delta_T);&lt;br&gt;
i=1+i;&lt;br&gt;
U1(i)=1/A_total;&lt;br&gt;
e=abs((U1(i)-U1(i-1))/U1(i));  % calculate error now but &lt;br&gt;
shif index by 1&lt;br&gt;
end&lt;br&gt;
U1final=U1(i)&lt;br&gt;
&lt;br&gt;
Yi</description>
    </item>
  </channel>
</rss>

