Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed.cs.wisc.edu!uwm.edu!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: for loop - variable increment
Date: Wed, 11 Jun 2008 17:31:26 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 40
Message-ID: <g2p25e$59m$1@canopus.cc.umanitoba.ca>
References: <g2p1ca$8sa$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1213205486 5430 192.70.172.160 (11 Jun 2008 17:31:26 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Wed, 11 Jun 2008 17:31:26 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:473330



In article <g2p1ca$8sa$1@fred.mathworks.com>, Mario  <nospam@yahoo.com> wrote:
>I want to test an algorithm with different values for the input variables.

>I thought to call my function inside a for loop but i want to increment the 
>input variable with a inconstant increment.

>e.g.
>for i=0.0001:i:1
>   test(i)
>end

You can't do that with a 'for' loop.

>so the first call would be test(0.0001), the second one test(0.0002), the third 
>one test(0.0004), then test(0.0008) and so on.

>I tried also the following way
>i=0.0001
>for j=0.0001:i:1
>   test(j)
>   i=j;       % or i=2*i;
>end

>but it doesn't work!

The 0.0001:i:1 part will be logically evaluated first, as if it
produced a vector of values, with j then being sequenced through that
vector of values.

Use a while loop instead.

i = 0.0001;
while i <= 1
  test(i);
  i = i * 2;
end
 
-- 
  "There is nothing so bad but it can masquerade as moral."
                                              -- Walter Lippmann