Array index out of bounds

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Array index out of bounds

Krishnaprasad
Hallo all,

I programmed a script which can train the system using SOM (Self Organizing Map). I used the SOMtoolbox for this implementation and it was programmed in Matlab. I migrated the code to Octave 3.8.0 and when I executed this code, I am getting Array index out of bound generated from one of the scripts of the SOMtoolbox. Further, I also notice that Octave 3.8.0 crashes when I call som_show() function that displays the GUI on how well the data is clustered.

Can I get suggestions from the forum to resolve the above problems?

Regards,
Krishnaprasad

Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

James Sherman
On Mon, Sep 22, 2014 at 9:01 AM, Krishnaprasad <[hidden email]> wrote:

> Hallo all,
>
> I programmed a script which can train the system using SOM (Self Organizing
> Map). I used the SOMtoolbox for this implementation and it was programmed in
> Matlab. I migrated the code to Octave 3.8.0 and when I executed this code, I
> am getting Array index out of bound generated from one of the scripts of the
> SOMtoolbox. Further, I also notice that Octave 3.8.0 crashes when I call
> som_show() function that displays the GUI on how well the data is clustered.
>
> Can I get suggestions from the forum to resolve the above problems?
>
> Regards,
> Krishnaprasad
>
>
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Array-index-out-of-bounds-tp4666628.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

I'm not familiar with this toolbox, but reporting the line that causes
the crash (or if you can recreate it) and what inputs you used will
probably help narrow down the problem.  Also, what steps did you take
to migrate the code?  If you had to change any part of the code, then
that may be where the problem lies.

James Sherman

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Krishnaprasad
Hi James,

I am running the code in linux from my windows laptop using X11 forwarding. I observed this crash when I tried using plot function too.

Is there any specific setting that needs to be set / enabled in Octave 3.8.0 if i have to use the GUI remotely?

Regards,
Krishnaprasad
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Krishnaprasad
This is the piece of code that generates Array index out of bounds:
Code:
 if ~isempty(content{j}) & (~isfield(content{j}(1),'type') | ...
                            ~strcmp(content{j}(1).type,'som_norm')),
        

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?
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Dmitri A. Sergatskov
In reply to this post by Krishnaprasad
On Mon, Sep 22, 2014 at 8:19 AM, Krishnaprasad <[hidden email]> wrote:
Hi James,

I am running the code in linux from my windows laptop using X11 forwarding.
I observed this crash when I tried using plot function too.


​I suspect the X11 server on your Windows is buggy​.
Can you run "glxgears" (at the  shell prompt, not octave prompt)?

 
Is there any specific setting that needs to be set / enabled in Octave 3.8.0
if i have to use the GUI remotely?

Regards,
Krishnaprasad


​Dmitri.
--


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Philip Nienhuis
In reply to this post by Krishnaprasad
Krishnaprasad wrote
This is the piece of code that generates Array index out of bounds:
Code:
 if ~isempty(content{j}) & (~isfield(content{j}(1),'type') | ...
                            ~strcmp(content{j}(1).type,'som_norm')),
        

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:

 if ~isempty(content{j}) && (~isfield(content{j}(1),'type') || ...
                            ~strcmp(content{j}(1).type,'som_norm')),
        

(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.

Philip
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Krishnaprasad
In reply to this post by Dmitri A. Sergatskov
Hi Dmitri,

The output of glxgears displays rotating gears and also prints the frame rate at regular intervals. Is this the expected output?

Regards,
Krishnaprasad
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Krishnaprasad
In reply to this post by Philip Nienhuis
Hi Philip,

I changed the code to && and || from & and |. I performed a quick test and could not find any error generated from the same line of code. The addition of double logical operator appears to have solved my problem.

Thanks for mentioning the reference links and also your suggestion.

Regards,
Krishnaprasad
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Krishnaprasad
In reply to this post by Krishnaprasad
With respect to the problem on octave crash, I added a line: graphics_toolkit("gnuplot"); and I was able to stop octave from getting crashed. I added the above line before the som_show command was executed.

Regards,
Krishnaprasad
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Krishnaprasad
When I get the console output on octave, I had to press either forward  (f) / quit (q) / next to see the complete output. Is there a command that I can set in the program using which I can reach the end of the prompt at the end of the program execution?
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Mike Miller
On Tue, Sep 23, 2014 at 06:07:34 -0700, Krishnaprasad wrote:
> When I get the console output on octave, I had to press either forward  (f) /
> quit (q) / next to see the complete output. Is there a command that I can
> set in the program using which I can reach the end of the prompt at the end
> of the program execution?

Try running "more off" first.

  http://wiki.octave.org/FAQ#I_am_running_a_script_that_should_produce_output_during_execution_but_I_don.27t_see_anything_until_it_has_finished

--
mike

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Andreas Weber-4
In reply to this post by Krishnaprasad
Am 23.09.2014 15:07, schrieb Krishnaprasad:
> When I get the console output on octave, I had to press either forward  (f) /
> quit (q) / next to see the complete output. Is there a command that I can
> set in the program using which I can reach the end of the prompt at the end
> of the program execution?

Disable the pager: "more off"
-- Andy

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Array index out of bounds

Andreas Weber-4
In reply to this post by Krishnaprasad
Am 22.09.2014 15:19, schrieb Krishnaprasad:
> I am running the code in linux from my windows laptop using X11 forwarding.
> I observed this crash when I tried using plot function too.

Please copy any errors or warnings verbatim. What X server are you
running on the windows side?

-- Andy

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave