Suppressing FaceVertexCData warning message in matlab - matlab

I recently updated my version of Matlab and since then I have been getting a warning message while using shading flat; The warning is:
Warning: Patch FaceVertexCData of size 0 cannot be used with Flat shading.
First off, the figures being produced look exactly as they should, but it still worries me. Could someone explain what this means or if it is important?
Secondly, if it is NOT important then how can I suppress the warning?

Considering part 2 of your question. First run:
warning on verbose
Then the next time you get the warning you will get an exact message describing how to disable that warning in the future. (The command will look like warning off <some_long_string>.)
More coarsely, you can simply use
warning off
Which turns off ALL warnings, but this is considered bad practice, since many warnings are very useful.

Related

Turning off warnings in Octave

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.

Finding location where Matlab warning was triggered

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

Auto fixing warnings reported by ScalaStyle

Is there a way to get ScalaStyle (or any other automation tool) to fix some of the warnings it finds?
For example --
Line contains a tab (shock!!)
There should be a space before the plus (+) sign
File must end with newline character
At a stretch
Public method must have explicit type
As of right now, Scalastyle does not have a way to automatically fix errors. However, it looks like Scalafix might. This is from their documentation:
A scalafix “Rule” can report lint messages and provide auto-fix patches to violations of some kind of rule/coding style/convention/breaking change.
Sounds promising! I have not had a chance to use it yet, but since this question has gotten no replies in almost three years, it seemed worth adding this as a possible solution to your problem if anyone else has a similar issue.

Unnecessary error in matlab

I have this error in matlab editor showing
an end might be possibly missing matching for
The code runs fine though, I am not sure why it is showing this error even when everything is matching. Any idea guys why this is so and how to remove this annoying red marker?
This is not an error, it's a mlint warning which should help you writing good code. In your case, the if and the end are not indented at the same level. Click on the if to see which end is matching.

MATLAB Warnings under fmincon

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