[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: n[:m]:end -- gap in the documentation?

From: Francesco Potorti`
Subject: Re: n[:m]:end -- gap in the documentation?
Date: Tue, 28 Apr 2009 08:33:19 +0200

>say you want to change every other element of a vector. You can do it like 
>b = [2, 5, 7, 0.2];
>b([2:2:max(size(b))]) += 4
>b =
>   2.0000   9.0000   7.0000   4.2000
>Someone, who is familiar with Matlab, pointed out to me that the
>second line can be written as
>b([2:2:end]) +=4;

Yes, this is the easiest way.  However, the first line was unnecessarily
complex.  First, 'max(size(b))' is the same as 'length(b)' for a vector.
Second, an alternative way for a row vector like yours is 'columns(b)'.

>This feature doesn't seem to be mentionend anywhere in the docs

Yes, Apparently it is missing.  These changes should be in order:

1) The Matrix chapter should explicitely define what a 'vector' is,
   possibly in a subchapter where what is a row vector and a column
   vector is defined

2) The Ranges chapter should mention the use of 'end'.

3) The Index Expressions chapter should reference the definition of
   vector and should reference the Ranges chapter.  It should also
   mention the use of 'end' in at least an example with explanation.

4) Maybe 'end' should also be mentioned as part of the Numeric Data
   Types chapter

Unfortunately I have not had any time recently to make additions to the
manual.  I am putting this in my todo list for Octave, but I am sending
it here also for comments and in the case that someone else takes over

Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]