help-octave
[Top][All Lists]
Advanced

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

Re: Non-integer indices in ranges


From: James Sherman Jr.
Subject: Re: Non-integer indices in ranges
Date: Tue, 2 Nov 2010 12:45:29 -0400

On Tue, Nov 2, 2010 at 12:33 PM, Martin, Cary <address@hidden> wrote:
Hello World - This issue is probably well known to the users of this
list but if I execute this code in Octave:

x = 0:1:10;
x(1.5:5);

This is received:
error: subscript indices must be either positive integers or logicals.

In Matlab I get:
ans =
    1     2     3     4

To a certain extent the Matlab response is of course ridiculous but is
there any simple way to get this behavior in Octave or otherwise work
around this issue? I've got some external legacy code which  seems to
expects this behavior which I'd like to use without extensive rewriting.

thanks-
Cary


My first stab at it would be to use a tool like awk or other tool with regular expressions to replace 
(*:*)
with 
(round(*:*))

where the * is the wildcard _expression_.  I think this is the behavior that Matlab is doing from your example, but I wouldn't be sure without seeing more examples of this behavior (maybe they're doing ceil and not round?).  What does Matlab do with 
x(1.1:5)
?

Hope this helps.


 

reply via email to

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