Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:18:03+00:00 2026-05-15T18:18:03+00:00

I’ve inherited some code where the author had an aversion to semicolons. Is it

  • 0

I’ve inherited some code where the author had an aversion to semicolons. Is it possible to fix all the mlint messages in one go (at least all the ones with an automatic fix), rather than having to click each one and press ALT+ENTER?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:18:03+00:00Added an answer on May 15, 2026 at 6:18 pm

    NOTE: This answer uses the function MLINT, which is no longer recommended in newer versions of MATLAB. The newer function CHECKCODE is preferred, and the code below will still work by simply replacing the call to MLINT with a call to this newer function.

    I don’t know of a way in general to automatically fix code based on MLINT messages. However, in your specific case there is an automated way for you to add semicolons to lines that throw an MLINT warning.

    First, let’s start with this sample script junk.m:

    a = 1
    b = 2;
    c = 'a'
    d = [1 2 3]
    e = 'hello';
    

    The first, third, and fourth lines will give you the MLINT warning message “Terminate statement with semicolon to suppress output (within a script).”. Using the functional form of MLINT, we can find the lines in the file where this warning occurs. Then, we can read all the lines of code from the file, add a semicolon to the ends of the lines where the warning occurs, and write the lines of code back to the file. Here’s the code to do so:

    %# Find the lines where a given mlint warning occurs:
    
    fileName = 'junk.m';
    mlintID = 'NOPTS';                       %# The ID of the warning
    mlintData = mlint(fileName,'-id');       %# Run mlint on the file
    index = strcmp({mlintData.id},mlintID);  %# Find occurrences of the warnings...
    lineNumbers = [mlintData(index).line];   %#   ... and their line numbers
    
    %# Read the lines of code from the file:
    
    fid = fopen(fileName,'rt');
    linesOfCode = textscan(fid,'%s','Delimiter',char(10));  %# Read each line
    fclose(fid);
    
    %# Modify the lines of code:
    
    linesOfCode = linesOfCode{1};  %# Remove the outer cell array encapsulation
    linesOfCode(lineNumbers) = strcat(linesOfCode(lineNumbers),';');  %# Add ';'
    
    %# Write the lines of code back to the file:
    
    fid = fopen(fileName,'wt');
    fprintf(fid,'%s\n',linesOfCode{1:end-1});  %# Write all but the last line
    fprintf(fid,'%s',linesOfCode{end});        %# Write the last line
    fclose(fid);
    

    And now the file junk.m should have semicolons at the end of every line. If you want, you can put the above code in a function so that you can easily run it on every file of your inherited code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.