From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: While loop fails
Date: Fri, 21 Oct 2011 19:57:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <j7siql$37t$>
References: <j7sh2e$q77$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1319227029 3325 (21 Oct 2011 19:57:09 GMT)
NNTP-Posting-Date: Fri, 21 Oct 2011 19:57:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2251561
Xref: comp.soft-sys.matlab:746729

"Julio Gonzalez" <> wrote in message <j7sh2e$q77$>...
> I am trying to get a while loop to work. I have an integer T, that I converted to double using the function double. But when I print the value of double T, it shows T as an integer and not as a double. Therefore my loop fails. This is the code:
> Ti=2
> T = double(T);
> to= 0.0000;
> while (T<=to) 
>     to = to+0.1;
>     %some code here.....
> end
> the loop end at to=2.0000; it should end at 2.1000
> Is there any other way to fix this problems besides T=2*(1+eps)?
> Regards
> Julio
> University of Liverpool


T is a double already. I think your example is supposed to look like this:

to= 0.0000;

while (to<=T) 
    to = to+0.1
    %some code here.....

The loop stops when to = 2. What are you trying to do?