range as in MATLAB/octave

Discussion in 'Perl Misc' started by Caj Zell, Jun 20, 2004.

  1. Caj Zell

    Caj Zell Guest

    Hello,

    in MATLAB (or octave) you write 0:5:20 get a vector that's 0,5,10,15,20.

    In perl I just did the following using the beginning, end and the interval.

    @ratios=map $_*$interval,$lower..($upper/$interval);

    Is there a nicer cleaner way using Perl?

    Caj Zell
     
    Caj Zell, Jun 20, 2004
    #1
    1. Advertisements

  2. Caj Zell

    Anno Siegel Guest

    Caj Zell <> wrote in comp.lang.perl.misc:
    > Hello,
    >
    > in MATLAB (or octave) you write 0:5:20 get a vector that's 0,5,10,15,20.
    >
    > In perl I just did the following using the beginning, end and the interval.
    >
    > @ratios=map $_*$interval,$lower..($upper/$interval);
    >
    > Is there a nicer cleaner way using Perl?


    As far as it has the semantics you want, that's one way of doing it.
    You may want POSIX::floor to get the right behavior for negatives.

    Anno
     
    Anno Siegel, Jun 20, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    4,796
    Kim Hansen
    Oct 8, 2009
  2. Replies:
    46
    Views:
    1,356
    Antoon Pardon
    Jul 25, 2006
  3. siki
    Replies:
    0
    Views:
    1,237
  4. Lambda
    Replies:
    2
    Views:
    593
    James Kanze
    Jul 16, 2008
  5. Luna Moon
    Replies:
    16
    Views:
    1,860
    Giovanni Gherdovich
    Aug 8, 2008
  6. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    290
    Tomoyuki Kosimizu
    Nov 27, 2003
  7. David Bird
    Replies:
    1
    Views:
    500
    Tiago Macedo
    Jun 23, 2008
  8. invis

    from octave to python

    invis, Jul 14, 2012, in forum: Python
    Replies:
    1
    Views:
    346
    invis
    Jul 14, 2012
Loading...