I think there is no easy way to get the line number and present it.
However, I usually deal with a situation like this:
Instead of displaying (or writing to the log) what line the current code is on, I show what this code does. Something like that:
% code disp('Accepting answer on Stack Overflow') % code...
Of course, you still need to worry about the functionality of your codes suddenly changing, but this requires careful processing.
If you really want to show the line number, this is the easiest way:
- Add something with a recognizable pattern, for example:
%LineNumberForDisplay<123> - Run a script that goes through the file, finds these patterns and replaces the number with the correct one
This update will need to be done before each run or after each change, which makes it a little impractical.
source share