How to display line number in command window when error occurs for R2014b?
142 views (last 30 days)
In all the previous Matlab versions that I have used, the line number where an error occurs has always been displayed in the command window. In more recent versions of Matlab it was even possible to click on the message, and then be transported right to that line in its m-file. This is in my opinion one of the absolutely most useful features of Matlab.
Then I installed Matlab R2014b on my new Macbook Pro (Yosemite). And no line number is displayed! I only error messages such as these:
Attempted to access timestamps(2,0); index must be a positive integer or logical.
Index exceeds matrix dimensions.
Please help me get back this functionality!
Image Analyst on 7 Feb 2015
I get a line number in WIndows. But try this:
% Some code that may generate an error.
% Some error occurred if you get here.
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
Ken Atwell on 19 Feb 2015
Command+Enter (equivalent to the "Run Section" button) will run just a section of code, not the entire file. In this situation, MATLAB doesn't have the full context of the file its operating in, which is why you're not getting line number information.
To run like the "Run" button, try F5 (I'm not sure why the other shortcut is not working for you). On my laptop, I actually need to press fn+F5 because a "plain" F5 is grabbed by my MacBook Pro to lower the backlighting on my keyboard.
You can always add your own keyboard shortcut; navigate to Home->Preferences->MATLAB->Keyboard->Shortcuts.