From: dpb on
Steven Lord wrote:
> "alfann" <alfann.net(a)hotmail.com> wrote in message
> news:1380396865.293654.1275931386222.JavaMail.root(a)gallium.mathforum.org...
....

>> Example:
>> DD=[1 3 4 8 9 10];
>>
>> for abc= min(DD(:)) : max(DD(:)) % start from 1 to 10 by one
....

>> I want to set the incremental is:
>> 1 then 3 then 4 then 8 then 9 then 10
>
> for abc = DD
> % do stuff
> end
>
> When you use this syntax, the FOR loop will iterate over the columns of DD,
> assigning each in turn to the variable abc.

Good catch, to read that the example used matched the array, Steve! :)

I didn't bother to think to check...altho gave the syntax as one of the
alternatives.

--


From: sscnekro on
Hi there,

I had the same question yesterday. Now having read the first post under this thread I realize by what I let confuse myself in the help doc. I mistakenly thought "Step s with values 1, 5, 8, and 17: for s = [1,5,8,17], ..., end" meant that the increment had an evolving size. After all, my post is worth deleting, as for s = [1,5,8,17] just assigned values 1, 5, 8, 17 to the step variable, precisely what is meant by the sentence - and there was no true reason for me to raise that question.

It will probably be worth nothing, but when digging into it yesterday I kept something in the command history, you may check out this:
for ii = [2,3,5,6,8,9]; b(1,ii) = ii^2; end
This just to say that it might depend a bit on the context in what you want to refer to your step variable. In some other contexts, it won't cause problems.
> s = [6,9];
> for ii = s;
> fid = fopen(sprintf('filename%d.txt', ii),'wt');
> fclose(fid);
> end
But I really did not explore it further and I doubt you would actually write any such command.
From: dpb on
sscnekro wrote:
....

> It will probably be worth nothing, but when digging into it yesterday I
> kept something in the command history, you may check out this:
> for ii = [2,3,5,6,8,9]; b(1,ii) = ii^2; end
> This just to say that it might depend a bit on the context in what you
> want to refer to your step variable. In some other contexts, it won't
> cause problems.

What's the problem perceived problem/novelty?

>> s = [6,9];
>> for ii = s;
>> fid = fopen(sprintf('filename%d.txt', ii),'wt');
>> fclose(fid);
>> end
> But I really did not explore it further and I doubt you would actually
> write any such command.

Why not...again, seems perfectly fine and ordinary to me; such is done
routinely and is indeed the subject of a very popular FAQ at the wiki.

It's prototypical ML syntax.

--
From: sscnekro on
> What's the problem perceived problem/novelty?

No, no, there is no novelty. It's just that I first hit on this yesterday and when writing a code I myself personally would easily mix up using such step values with a reference on some places in the code that assumes increment of size one.

This is what I started to imagine yesterday is meant by hlp doc, that one would be able of setting for s = initval: [1,5,8,17] : endval so that s would take values initval, initval + 1, initval +1+ 5, etc. until endval is reached.

PS dpb, don't let confuse yourself by some of my posts written from a commercial product customer's point of view, with my posts on programming and using ML. I know where my place is on the newsgroup wrt the latter. For you as an 'Old Guy' (old in the sense of huge programming and problem solving experience) there will never be novelty in my posts.
From: dpb on
sscnekro wrote:
....

> This is what I started to imagine yesterday is meant by hlp doc, that
> one would be able of setting for s = initval: [1,5,8,17] : endval so
> that s would take values initval, initval + 1, initval +1+ 5, etc. until
> endval is reached.
....

That _doesn't_ work...to see, try

1: [1,5,8,17] : 20

from the command line (which simply assigns values to initval and endval
explicitly)...

--