Why does text command give warning while publishing strings in matlab - 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

Related

Clear previously printed message with fprintf

While executing a script, I have used
msg='Please wait...';
a=fprintf('%6s\n',msg);
fprintf('\n');
before the results get displayed. However after the results disclosure on the screen "Please wait..." is still appearing although I used
clear a
Thus, is there a way of turning off in the code
fprintf()
Clear a: the clear function delete the selected variable from the memory. To clear the console you have to use clc.
But you can also comment or delete the line where fprintf is called.
As already stated you have to use clc to clear the command window.
You can also erase just the last characters by inserting multiple backspaces. For instance:
fprintf(repmat(char(8), [1 numel(msg)]));

matlab debugger no longer displays output [duplicate]

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.

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

undefined variable in MATLAB

I am newbie to MATLAB .I have written a code to upsample a data.when executed always shrows the particular error(below)
??? Input argument "n" is undefined.
Error in ==> upsamp at 7
mm=min(n)
but when i just write the foll. output [n1,y]=upsamp([1,2,3,4,5,6],-1:4,3) command window ,its shows me the correct upsampled data with its figure.
then why the error is popping up? Or i just click on run button,and error is shown in command window.
Please help me out to debug that error:
My code is
function[n1,y]=upsamp(n,x,I)
mm=min(n)
mx=max(n)
n1=mm*I:(mx*I+I-1)
x1=x'
x1=[x1,zeros(length(x),I-1)]
x1=x1'
y=(x1(:))'
subplot(2,1,1)
stem(n,x)
title('original sequence ')
xlabel('Range')
ylabel('sequence')
subplot(2,1,2)
stem(n1,y)
title(' unsampling')
xlabel('Range')
ylabel('sequence')
end
As others have noted, if you want to run a function that takes input arguments, you have to call it manually from the command prompt with any required arguments.
Otherwise, if you like to use the Run button (F5) from the editor, consider creating a run configuration (they can be used in smart ways)
The "run" button is only for scripts (i.e. just a plain list of statements without "function" at the top). This is a function, so it should only get called from the matlab command line like you described.
The run button calls your function with no arguments.
Since arguments to your function are non-optional, you get an error.
Either call your function from the interactive Command Window, or write a short script that provides appropriate arguments, and use the Run button with that script. You can still single-step into your function.