[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about Range class
From: |
Robert A. Macy |
Subject: |
Re: Question about Range class |
Date: |
Tue, 22 Nov 2005 20:28:57 -0800 |
For some reason, my brain assumed *no* octave code, but
that doesn't make much sense. Even in that case there are
things to use in the Standard Library to allow variable
size and automatic destruct.
Just curious, why is the order of the arguments...
Range r (0.0, 10.0, 0.1); // base, limit, increment
...and not...
Range r (0.0, 0.1, 10.0); // base, increment, limit
...to keep a similar order of arguments in octave's...
z = [ 0 : 0.1 : 10 ]
...?
- Robert -
On Tue, 22 Nov 2005 20:28:53 -0500
"John W. Eaton" <address@hidden> wrote:
> On 22-Nov-2005, Robert A. Macy wrote:
>
> | >From a newbie and untested...
> |
> | double z[100];
> |
> | for (int i = 0; i < 100; i++)
> | z[i] = 0.1 + ( static_cast<double>(i) )/10.0;
>
> Octave has a Range class for this kind of operation, so
> you don't have
> to do it by hand. Note that your code assumes you know
> precisely how
> many elements are in the range. If someone just hands
> you the base,
> limit, and increment for the range, are you sure you
> could calculate
> the best approximation of the number of elements? Do you
> think it is
> a simple calculation? You might be surprised by the
> answer (take a
> look at the code that does this in src/Range.cc)!
>
> | Marek Szczypinski <address@hidden> wrote:
> | > Hello,
> | > how should I write
> | > z = [ 0 : 0.1 : 10 ] in c++?
> | > thanks,
> | > marek
>
> For 0:0.1:10, try
>
> Range r (0.0, 10.0, 0.1); // base, limit, increment
>
> In Octave, if you write
>
> [0:0.1:10]
>
> the result is actually a Matrix object, so you would need
> to write
>
> Range r (0.0, 10.0, 0.1); // base, limit, increment
> Matrix m = r.matrix_value ();
>
> jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Question about Range class, Marek Szczypinski, 2005/11/22
- Re: Question about Range class, Robert A. Macy, 2005/11/22
- Re: Question about Range class, John W. Eaton, 2005/11/22
- Re: Question about Range class, Pedro Antonio Fructuoso Merino, 2005/11/23
- Re: Question about Range class, Robert A. Macy, 2005/11/23
- Re: Question about Range class, Shai Ayal, 2005/11/24
- Re: Question about Range class, John W. Eaton, 2005/11/24
- Re: Question about Range class, Joe Koski, 2005/11/24
- Re: Question about Range class, Miroslaw Kwasniak, 2005/11/25
- Re: Question about Range class, Robert A. Macy, 2005/11/25
- Re: Question about Range class, Przemek Klosowski, 2005/11/25