Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Does checkcode return the status of the "Message indicator box", i.e. red/orange/green ?

Asked by per isakson

per isakson (view profile)

on 27 Nov 2012

I search for an automatic way to find out if a file has a syntax error. That is, to find the same piece of information that the Code Analyzer indicates with red in the "Message indicator box" of the editor.

I took for granted that checkcode provides the information corresponding to the colors of the "Message indicator box".

Doc (R2012a) says:

    [...] checkcode('filename') displays messages, sometimes referred to as 
    Code Analyzer messages, [...]

thus, I tried

    info = checkcode( filespec );

and

    info = checkcode( filespec, '-id' );

However, I cannot find the piece of information I need. isempty(info) equal to true indicates green, but, I cannot figure out how to find an indicator for red. (Not empty indicates red or orange.)

One way would be to have a list of the ID, which stands for errors.

I did check http://undocumentedmatlab.com/

5 Comments

Image Analyst

Image Analyst (view profile)

on 30 Nov 2012

Sounds like he's trying to make his own mlint functionality. Not sure why since this functionality already exists in MATLAB.

Sean de Wolski

Sean de Wolski (view profile)

on 30 Nov 2012

It sounds like he'd like to be able to test whether a file has syntax errors before running it - sounds fair to me...

per isakson

per isakson (view profile)

on 30 Nov 2012

Yes, I want to check for syntax errors as the first step when running a test suite.

per isakson

per isakson (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Yair Altman

Yair Altman (view profile)

on 1 Dec 2012
Edited by Yair Altman

Yair Altman (view profile)

on 8 Dec 2012
Accepted answer

I must admit that I have it on my articles TODO list for quite some time...

Here's something to get you started: http://www.mathworks.com/matlabcentral/newsreader/view_thread/255839#755939 (continue reading down the thread)

Related: http://www.mathworks.com/matlabcentral/newsreader/view_thread/145245 (oddly enough, you were part of that thread, Per...)

Also related: http://www.mathworks.com/matlabcentral/answers/15929-use-of-mlintmex-in-mcc-deployed-code

In summary, you could simply do:

errMsgs = mlint('-m2',srcFileNames); % m2 = errors only
m1Msgs  = mlint('-m1',srcFileNames); % m1 = errors and severe warnings only
allMsgs = mlint('-m0',srcFileNames); % m0 = all errors and warnings

Note that mlint returns the data in struct format, while mlintmex returns a string that you must parse.

Yair Altman

http://UndocumentedMatlab.com

0 Comments

Yair Altman

Yair Altman (view profile)

Answer by Sean de Wolski

Sean de Wolski (view profile)

on 30 Nov 2012

It looks like you could use try/catch and do an isempty check on the ME.stack:

%checkcodetest.m
X = [pi    
for ii = 1:3
disp('hi')
end

And:

try;
 checkcodetest;
catch ME;
end

Now to test:

isempty(ME.stack)

0 Comments

Sean de Wolski

Sean de Wolski (view profile)

Contact us