[Top][All Lists]

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

Re: Array index out of bounds

From: Philip Nienhuis
Subject: Re: Array index out of bounds
Date: Mon, 22 Sep 2014 13:53:28 -0700 (PDT)

Krishnaprasad wrote
> This is the piece of code that generates Array index out of bounds: 
> Code:

> Does Octave use a different approach to check the field is empty? I have
> seen a similar error thrown from another place in the same matlab file.
> Are any of these conditions not suitable in Octave?

Just try:

(i.e., && and || rather than single & and | )

Yes Octave has a different way of short-circuiting in logical expressions. 

I think what happens in your code is that -contrary to Matlab- Octave tries
all logical sub-expressions, rather than quitting if it can determine that
the entire expression is true or false, *unless* you specify double logical
operators. If you do, Octave does do short-circuiting.
If j is out-of-range, or content{j}(1) is empty, you'll see this crash.

If I'm right your Matlab code is -sorry to say- another example of sloppy
and fragile Matlab programming. But I may speak too early :-)

BTW this difference in behavior is described in the  FAQ
<>  . 
Some parts of this FAQ entry are not valid anymore (The Mathworks did mend a
few things) but your problem is adequately described there.


View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

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