MATLAB Answers

0

How does one identify the current line being evaluated during execution?

Asked by Tolulope on 15 Jan 2013
Latest activity Answered by Pruthvi Raj Gampalwar on 20 Mar 2019
I would like to know if there is a command in MatLab that returns the value of the line number on which it has been executed.
For example:
1
2 for i = 1:10
3 % some line of code
4 currentLine = ?;
5 end
6
7
8
9
Where "?" is some MatLab command or function (if it exists) that identifies the line on which "?" is called, in this case line number 4.

  1 Comment

I suggest:
function line=currentline
s=dbstack;
line=s(2).line;

Sign in to comment.

3 Answers

Answer by Wayne King
on 15 Jan 2013

Look at the help for dbstop
For example:
dbstop in FILESPEC at SUBFUN

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 15 Jan 2013

I don't know why you need the number. You can issue the "echo on" command and it will spit out the current line being executed to the command window, without a line number though. When you have functions and other m-files, the concept of line number becomes not so clear.

  0 Comments

Sign in to comment.