matlab debugger no longer displays output [duplicate] - matlab

I'm not entirely sure how, but my copy of MATLAB R2013b has stopped showing which line my errors occur at.
I'll just get errors like:
Subscripted assignment dimension mismatch.
But no line number to go along with it, so I have no idea which part of my code is causing the problem!
Did I mess up a setting somewhere?

Enable line numbering in the editor with Preferences -> Editor/Debugger -> Display -> Show line numbers
When running code segments (for example, using Ctrl+Enter with the Windows default key bindings), line numbers will not be displayed. You can see the line on which the error is caused by directly running the script or calling the function in which it occurs.

Related

Why does text command give warning while publishing strings in matlab

When i use the text command, it does do its work but gives a warning:
Warning: Error updating Text. Following is the chain of causes of the
error:
String must have valid interpreter syntax:
^
The trouble is when i have to use the text command in a for loop 1000 times, the entire command window gets flooded with warnings which is sometimes inconvenient. I use the text command as follows.
figure();
set(gca,'YAxisLocation','Right','YDir','reverse')
axis([0 11 0 11]);
daspect([1,1,1])
rectangle('Position',[2,3,1,1])
text(5,6,'^');
view([-90 -90])
is there a work-around? I don't want the warning to be displayed. What is causing the warning?
EDIT:
Is there a way to put text in plot in matlab in any other way where this will not be encountered?
Characters like ^,\, etc are interpreted in a pre-defined manner in Matlab hence pose difficulty. Use:
text(5, 6, '\^');
Set the interpreter to "none".
For example:
text(1,1,'c:\games\digger','interpreter','none')
This applies also for TITLE, XLABEL and other similar commands.
I couldn't reproduce you problem (Ubuntu, R2014b). However, to get rid of warning messages you can simply disable/enable the warnings around your problematic line:
warning off
text(5, 6, 'T');
warning on

MATLAB Debugger no longer showing line numbers

I'm not entirely sure how, but my copy of MATLAB R2013b has stopped showing which line my errors occur at.
I'll just get errors like:
Subscripted assignment dimension mismatch.
But no line number to go along with it, so I have no idea which part of my code is causing the problem!
Did I mess up a setting somewhere?
Enable line numbering in the editor with Preferences -> Editor/Debugger -> Display -> Show line numbers
When running code segments (for example, using Ctrl+Enter with the Windows default key bindings), line numbers will not be displayed. You can see the line on which the error is caused by directly running the script or calling the function in which it occurs.

How to debug matlab code without gui

I have recently started using MATLAB without GUI by starting matlab with -nodesktop option and it is considerably faster.
However presently I have no way to debug a .m script in non gui mode. I have to open the default matlab editor every time I have to debug.Has anyone figured out a way to do it?
Thanks in advance
I am using Ubuntu Linux, in case that helps.
To set breakpoints with the command line, dbstop is the tool (plus dbclear to clear breakpoints and dbstatus to list them).
There are presently 17 different forms to dbstop, which allow you to specify various combinations of:
The M-file in which to stop
Line number
Sub-function
Conditional to an arbitrary expression. For example,
dbstop in myFun.m at 224 if ~exist('x','var')
At any run-time error (dbstop if error)
At a specific error (e.g dbstop if error myFun.m:barErrorId)
At any warning (dbstop if warning) or specific warning
If NaN or Inf are encountered (dbstop if naninf)
See the documentation for dbstop for details and good examples.
Also get used to dbcont (or F5), dbstep (or F10), dbquit (Shift+F5), dbstep (also dbstep in, dbstep out), dbstack (to see where you are and how you got there). The keyboard shortcuts may be different outside of Windows.
Far less used, but still very useful are dbup and dbdown, which allow you to switch workspace context (memory stacks).
See the summary of functions and a list of examples and how-to pages in the MathWorks page on Debugging.
Related to the "db" functions is checkcode, which will check your code for possible problems before you even run it. This is a nice substitute for the red squiggly underlines that you would get in the MATLAB Editor.
Once you get a hang of dbstop and it's syntax, you won't often need to insert a keyboard into your code, but it's always an option.
Try placing the keyboard command in your code to insert a breakpoint. When the keyboard command is reached, MATLAB will drop into an interactive prompt that you can use to inspect variables. For example:
x = rand(10,10);
y = rand(10,5);
z = x * y;
keyboard; % you can interactively inspect x, y, z here
z = sort(z);
To leave keyboard mode, you can type dbquit to exit the program, or return to continue executing the program.
Another trick is to turn on dbstop if error which will automatically drop you into an interactive prompt whenever your code crashes.
You can use MATLAB -Dgdb if that helps. This sets gdb as the debugger. You will need to be familiar with gdb of course.
Once you do that, use the standard gdb commands to debug it.
EDIT
My mistake. Above won't work for M-Files. (Not having MATLAB to try things out is a pain :)
MATLAB has a pretty good set of debugging commands you can use from the commandline. If you insert keyboard commands in your MATLAB code, you can then use the commands.
You can use MATLAB's editor debug button to debug within MATLAB environment

Show Line Number in Error Message

On most instances of MATLAB I've used, whenever I had a bug in my code the error message in the command window would show the line number.
However on the computer I am currently using, it shows me only the following:
??? Subscripted assignment dimension mismatch.
Is there anyway to get the line number to show again instead of ?????
What you are doing is using Run Section or Run and Advance as #canzar said. If you run scripts like this there is no 'line number', just as when you copy-paste code and run it in the command-window will not show you the line number on the error.
If you run the script using run or by pressing F5 it does know the line number and then prints that on the error statement. Good to know for debugging is to go to the tab editor->breakpoints->dbstop on error. If you press that it will keep your variables as present when the memory occurs, as opposed to throwing everything out when debugging functions.

Disable auto-scrolling in command window

A lot of the code that I write in Matlab has a very verbose output. As the program runs, information is printed to the command window, and with each new line, the window automatically scrolls to the bottom. This becomes a problem when I want to read some of the output more closely or scroll up to look at older output. I can scroll up, but only until a new line is printed, which is often less than a second.
Does anyone know if it is possible to turn off this automatic scrolling in the Matlab window? I work in a number of different Matlab versions, depending on the machine, and this happens with all of them. The answer to this might be "No", but I swear I remember having this functionality at one point.
Use the more function: http://www.mathworks.com/help/matlab/ref/more.html
more on
Then run your program. Press spacebar when you wish to see more of the output.
more off will turn it off.
You may find this workaround useful.
First launch matlab using the command line matlab -logfile 'myLog.txt' (the doc says it "starts MATLAB and makes a copy of any output to the Command Window in filename. This includes all crash reports.")
Then open your .txt file using a text editor supporting automatic refresh of content (see picture). On OSX I use TextWrangler (freely available at www) but others have been reported to have this feature (see here or here).
Results: output displays (fprintf, disp, but not the commands per se) are printed both on the Matlab console and the text editor (file is refreshed with a little lag time, below half a second I would say with my configuration). And there is no automatic scrolling. Such procedure does not seem to impact the overall performance of the script (although it may deserve some testing).