How to display static analysis warnings in MATLAB? - matlab

I've noticed the MATLAB editor will often show quite helpful warnings for ".m" files. As I tend to run my MATLAB code remotely I prefer not to use the MATLAB editor, instead keeping open a long running emacs session. It would be great if these warnings could be printed out when running a script, perhaps if some setting was enabled (I could imagine not wanting to do that by default for performance). Is this possible?

I believe you're looking for checkcode. From the documentation:
checkcode(filename) displays messages about filename that report potential problems and opportunities for code improvement. These messages are sometimes referred to as Code Analyzer messages. The line number in the message is a hyperlink that you can click to go directly to that line in the Editor. The exact text of the checkcode messages is subject to some change between versions.
...
info = checkcode(___,'-struct') returns the information as an n-by-1 structure array, where n is the number of messages found.

Related

How to filter out problems in VSCode based on text?

I'm using VSCode 1.41.0 on Windows 10 x64.
In my code (which is in a research language you've likely never heard of), there is a certain class of warning message I get a lot of in the Problems panel, and I want to ignore those messages. The text of the message varies a bit across instances, but it always contains the word "duplicate". How can I filter out problems containing "duplicate"? The text filter that already exists keeps problems containing the specified text, and I want the opposite.
I tried !duplicate but it didn't seem to do anything.
Not the answer you are looking for, but negative filters currently only work with glob patterns, not with text. This is a known issue with the filter feature of the problem panel in vscode. You can check the progress here: https://github.com/microsoft/vscode/issues/62531

Matlab: hide stout (no evalc)

I have read several posts here and in other forums to understand how to do hide the output of a function on the command window. Generally, the answer is: "use evalc".
Today I posted another question for a different issue (Memory issue with Matlab: update variable in .mat) and a user showed me why it is always better to avoid the usage of eval/evalc (How to put these images together?).
What if I want to avoid evalc but I want to hide the output of a function from the command windows? Is it possible to do it?
EDIT:
I don't think it is a duplicate.
As said in the introduction there are several posts (also here in stack overflow) that address this question. But (including the post which should be a duplicate of this question: Suppressing a function's command window output ) the main answer is to use evalc, which as written in the title, I don't want to use. Also, as written in the link above, using a private disp might be risky, it is not going to suppress outputs resulting from fprintf or from a missing semicolon (creating also a private fprintf would hide also some output string that I want to have).

Tips on optimizing this code that loads multiple files in Matlab?

fname = dir('*sir');
dayH = zeros(length(fname),1360,3600);
for i=1:length(fname)
dayH(i,:,:) = loadsir(fname(i).name);
end
fname = dir('*sir');
dayH = cell(1,length(fname));
for i=1:2
dayH{i} = loadsir(fname(i).name);
end
Basically it loads all my files. I have a separate .m file called loadsir that loads those specialized files. The output of the .sir files will be an array 1360x3600.
Right now that code is crashing saying, "Cannot display summaries of variables with more than 524288 elements." I guess it's because 1360X3600 = 5,000,000 about?
Putting Serg's comment as an answer:
Most likely you missed a semicolon (;) somewhere in loadsir. Matlab then thinks you want to print the output, which it won't do due to the large number of elements.
Additionally, to prevent such things from happening in the future:
Matlab is an interpreted language, meaning, no compilation is necessary. Any and all code can be parsed while you type it, which allows for things like auto-correct. Of course, this sort of thing is included already in standard Matlab. If you don't already, code in Matlab's own editor every now and then. It warns you of such silly mistakes/errors (and a lot more), including but not limited to, via the right vertical bar in the editor. The little square at the top right of the window should always be green. If it's orange or red, there's things to be improved or corrected, respectively.
The right vertical bar is an overview of all the lines in your file that leave room for improvement. If a small orange/red bar appears somewhere, a mouseover will tell you what's wrong with what line. Clicking it will navigate the editor to the line, which will likely be wavy-underlined in either orange or red. Mouse-over the line often gives useful suggestions, and <alt>+<enter> is often enough to fix the simple mistakes. I find it an indispensable tool when developing larger applications in Matlab.
You can of course configure which errors/warnings this tool ("code analyzer", formerly "mlint") displays. Sometimes, there will be a warning about an inefficiency that you simply cannot work around. Add an OK-directive behind the line to suppress it (%#ok), but don't make a habit of suppressing anything and everything "annoying" because that will of course completely beat the purpose of the code analyzer :)

How to work with logfiles

Usually I pipe my log through a lot of greps to remove the "noise" before i open it in an editor.
I think it should be possible to do this filtering inside an editor (Especially Emacs)
Is this what chainsaw is doing? For log4j format only or more general?
(It is the only logfile viewer tool I can find)
How do you guys do it?
(I think UNIX grep syntax would be easiest for me)
Chainsaw does support both positive and negative filter matching. You can define positive and negative matches based on the logger tree (right click on nodes for the options), and you can define positive-match expressions in the 'refine focus' field, and negative-match expressions using the 'ignore' option below the logger tree. There is a tutorial available from the help menu which describes the expression syntax.
Chainsaw has had a lot of new features added since the last official release. The developer snapshot (including a reworked configuration screen) is available here:
http://people.apache.org/~sdeboy
Chainsaw doesn't just work with log4j. There are 'receivers' available that make it work with log4net, java.util.logging, log4php and others.
You can also process any regularly formatted text file using a VFSLogFilePatternReceiver (use the 'process a log file' option to configure Chainsaw to define one). There are some pre-defined log formats in the configuration dialog that act as example formats - tweak one to match your format. The JavaDoc provides more information: http://logging.apache.org/chainsaw/apidocs/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.html
If the greps are the same, you can simply code a script to do all that work for you (e.g. vimscript for vi). That way, you don't have to repeat all the tasks while leaving the logs intact for further investigation.
You're right on chainsaw and log4j - it's a logging viewer with different capabilities, e.g. a filter mechanism. However, I am unsure, if you are able to have multiple filters activated simultaneously.
Yes, you should try Chainsaw first.. it does support various ways of getting your logs.
Necroposting: I created a mode for Emacs that is specifically targeted at Log4j-like logs, but supports many more formats, especially if you customize it for yourself.
Features:
Colorization (just customize faces if that's too much)
Interactive filtering in the same buffer:
by level
by logger name
by thread
by message
easy narrowing
edit all currently set filters at once
A few log-specific movement commands
Copy (with M-w) only visible text, goes well with filtering (this is customizable)

Tool to compare/diff HTML in bulk

I have a lot of HTML files (10,000's and GBs worth) scraped from a server and I want to check to make sure the server produces the same results after some modifications but ignore kinds of differences that don't matter, e.g. whitespace, missing newlines, timestamps, small changes in some kinds of number, etc.
Does anyone know of a tool for doing this? I'd really rather not do more filtering than I have to.
(Oh and it needs to run under linux)
You might consider using a clone detector such as our CloneDR. This tool parses large sets of computer program (HTML is special case) files, builds abstract syntax trees representing the essential structure of each files, and compares programs for similarity.
Because it is comparing essential program structure, it ignores inessential differences such as comments and whitespace, and deterimines that two code segments are either identical or one can be obtained from the other by substituting other blocks of code. The latter allows the recognition of code that has been modified in various ways. You can see samples of clone detection runs on a variety of computer languages at the web site.
In your case, what you would be looking for are files in system A which are essentially clones (exact or near misses) of files in system B. As a general rule, if a file a is a variant of file b (e.g., with a few changes) the CloneDr will report it as a clone and show the exact differences.
At the scale of 20,000 files, I can see why you want a tool, and I can see why you want near-miss matches rather than exact matches.
Doesn't run under Linux, but I assume your problem is hard to enough to solve so that isn't what you are optimizing.
I use winmerge alot in windows and from what i can see some people enjoy meld in linux, so perhaps that could do the trick for you
http://meld.sourceforge.net/
Other examples i saw from a quick googling was Kompare,xxdiff.sourceforge.net, and kdiff3.sourceforge.net
(could only post 1 link so wrote the adresses to xxdiff and kdiff3 as text)
Beyond Compare is purchased software that is actually worth the money (I never thought I'd hear myself typing that!). It is GUI based but handles thousands of files very well. It will allow you to specify unimportant changes with regular expressions as well as whitespace (beginning, middle and end of line). The feature set is very extensive, check out a trial download.
I do not work for this company, I just use Beyond Compare every day at work and enjoy it every time!