Script Kitty
Script Kitty

Reputation: 1747

Octave Get line number of error

The error I'm getting is not very descriptive, it will tell me

error: gradientDescent: product: nonconformant arguments (op1 is 1x97, op2 is 97x2)

I know the file is gradientDescent.m, but is there a way to get the line number of the error?

Upvotes: 0

Views: 944

Answers (1)

Brent Baccala
Brent Baccala

Reputation: 1007

lasterror() contains a stack trace.

In my application, I'm getting the message "error: plot: properties must appear followed by a value", with no line number.

After I get the prompt back, I can example the stack trace like this:

octave:23> lasterror().stack
ans =

  6x1 struct array containing the fields:

    file
    name
    line
    column
    scope
    context

octave:24> lasterror().stack.file
ans = /usr/share/octave/4.2.2/m/plot/draw/private/__plt__.m
ans = /usr/share/octave/4.2.2/m/plot/draw/plot.m
ans = /home/baccala/WAM/waveletauditory/SOM-Toolbox/som/vis_trajgui.m
ans = /home/baccala/WAM/waveletauditory/SOM-Toolbox/som/vis_trajgui.m
ans = /home/baccala/WAM/waveletauditory/SOM-Toolbox/som/vis_trajgui.m
ans = /home/baccala/WAM/waveletauditory/SOM-Toolbox/som/vis_trajgui.m
octave:25> lasterror().stack.line
ans =  96
ans =  223
ans =  616
ans =  567
ans =  548
ans =  253
octave:26> 

Which tells me that the troublesome call to plot in on line 616 of vis_trajgui.m.

Upvotes: 2

Related Questions