I have a large codebase in Matlab (2021a Update 5, running on Mac) which triggers the warning:
Warning: Integer operands are required for colon operator when used as index.
But there is no information about where this warning is triggered. How can I find out what file and line-number it came from? So I can adress the problem.
Cris Luengo provided an excellent solution in a comment, so I thought I might repeat it and flag the question as answered.
To break the execution at the first line that's triggering a warning, run the following command in the Command Window beforehand.
dbstop if warning
From what I can tell, the following command resets this option.
dbclear all
Related
I am running a Matlab compatible script in Octave, so I was awaiting few warnings concerning the '&' and '|' commands and others, so I added the "warning('all','off')" in my now Octave script, but it doesn't seem to do anything... I don't get it, I still get the same warnings!
Any ideas how to solve this please?
PS: I am running the Octave script in batch mode.
It should be warning('off','all') or just warning('off'), your arguments are inverted.
Docs: https://octave.sourceforge.io/octave/function/warning.html
warning ("off", id)
If the first argument is "on" or "off", set the state of a particular warning using the identifier id. If the first argument is "query", query the state of this warning instead. If the identifier is omitted, a value of "all" is assumed.
Obligatory note that it's probably a better idea to address the warnings than turn them off, and that you should at least re-enable the warnings after specific functions where you want to ignore them.
In Matlab, which('filename', '-all') returns all the files with the given 'filename' in the Matlab path, but Octave only returns the first one (not the shadowed ones). Is there an easy way get the equivalent in Octave?
this is a longstanding feature request for Octave that as of this post has not yet been resolved. See Bug #32973 and Bug #32088. The latter link appears to have a workaround patch and function attached that never quite made it into the main codebase.
UPDATE 16 Nov 22: while the bug has not been fixed, rather than silently fail Octave v8 will now provide a warning to the user that the option is not yet implemented and only the first result will be returned.
I am trying to read the following internal MATLAB function:
>>which visionInitializeAndExpandCheckerboard
built-in (C:\Program Files\MATLAB\R2015a\toolbox\vision\vision\visionInitializeAndExpandCheckerboard)
But it appears to be hidden away! And very well hidden.
None of the following methods to access it have worked:
Highlighting the name and pressing Ctrl+D.
Typing "edit visionInitializeAndExpandCheckerboard" in the command line.
Searching for the file in Matlab's own FindFiles.
Searching for the file on the disk.
Trying to Step Into the function in debug mode (I just get the output as if I had requested Step Out instead).
Btw, the reason I am looking into this is that the parent function detectCheckerboardPoints has seriously declined in performance from R2015a to R2016b and I am trying to figure out why.
The internal function is compiled native code, so you will not be able to see its source. If you see a performance degradation, you should call Mathworks tech support and complain. If it is something they can fix, they will send you a patch, and fix it in the next release.
I'm minimizing a function with the fmincon routine.
This function uses the integral command several times. However, some of those integrals turns out to be Inf or NaN and I don't want MATLAB to show a warning when this happens (the function is always finite).
I've tried using the command warning('off','MATLAB:integral:NonFiniteValue') but it don't seem to be working when running the optimization.
It could be you're simply suppressing the wrong message. You could inspect the values of
[a,b] = lastwarn
inside an output function (opts = optimset('OutputFcn', #myOutFcn);) to make 100% sure you're killing the correct warning message.
But I too have encountered this annoying behavior before -- you just can't seem to suppress certain warnings in MATLAB's own functions. For those, you have to resort to ugly and fragile hacks.
You could try
warning off
...
warning on
which suppresses all warnings for all code contained in the '...' section.
You could also use an undocumented feature: temporarily promote the warning to an error:
ws = warning('error', 'MATLAB:integral:NonFiniteValue');
...
warning(ws);
and wrap it up in a try....catch. Chances are you then interrupt integral and thus fmincon prematurely and will thus have to wrap it up together with some rescue mechanism, but that gets real complicated and real ugly real fast, so that's only to be used as a last resort...
...so in all, it's easiest to just live with the warnings.
There's an alternative way: click on the uppermost link in inner matlab files that produced that warning, find warning ID & copy it into clipboard.
Then add the following line to your script:
warning('off','IDHERE');
Replace IDHERE with actual ID
See https://tushev.org/articles/blog/17/how-to-suppress-matlab-warnings
I never work with the GUI and am always inside a terminal (also full screen, so no title bar) set with the -nodesktop -nodisplay option. I also have different servers that I connect to, to run matlab and each of those have different restrictions on hogging computational resources. Since it's hard to remember which server I'm in,especially if I have multiple sessions open, I was wondering if I could change the prompt to display the server name. Try as I might, I couldn't find a resource that explains how to go about it (I'm beginning to think Mathworks doesn't support it). I know, a workaround would be to simply write a function call to system('hostname') and put the function in the path, so that it's about as easy as typing pwd to find the directory. I'd like to know if there's something more elegant.
There is a submission on the MathWorks File Exchange that can do this for you: setPrompt by Yair Altman. Using it in R2010b, I noticed that I was getting the warning message:
Warning: Possible deprecated use of set on a Java callback.
> In setPrompt at 115
Which I was able to suppress using the warning function like so:
warning('off','MATLAB:hg:JavaSetHGProperty');
And here's how I changed the prompt to the host name using the system function:
>> [~,systemString] = system('hostname');
>> setPrompt([deblank(systemString) '>> ']);
P11-4504>>
The function deblank is used to remove trailing whitespace (in this case a newline) from the string.
NOTE: The above changes (suppressed warning and modified prompt) don't persist after you quit and restart MATLAB, so you could put the above code in your startup.m file to apply them automatically every time you start a new session.