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

  • SEARCH
  • Home
  • 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 3697208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:49:56+00:00 2026-05-19T04:49:56+00:00

I have a complex MATLAB-Simulink project involving many m-files and mdl-files. Some m-files define

  • 0

I have a complex MATLAB-Simulink project involving many m-files and mdl-files. Some m-files define variables that are used in other m-files (bad design, I know, but it is legacy code). There are also functions that aren’t used anymore.

I need an automatic way to find unused variables and functions so that I can delete them and make the whole thing a little less complex. Ideally I should have a script/tool which takes as input the name of root directory of the project, scans all the files in subdirectories, and outputs all the variables and functions that are not used in any m-file or mdl-file.

I know that I can find variables that are not used in mdl-files (see Tips and Tricks – Tracking Variables in a Simulink Model). I would like to apply that method to all the files in the project.

My idea to detect variables not used in m-files is to temporarily combine all the m-files into a single file and run mlint on it. Any better ideas?

  • 1 1 Answer
  • 3 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-19T04:49:56+00:00Added an answer on May 19, 2026 at 4:49 am

    Instead of going through the tedious (and potentially error-prone) task of pasting all of your m-files into one to run MLINT, you have a few other options…

    If you have all your files in one folder, the simplest approach is to go to the Current Folder browser, click the Actions button alt text, and then select Reports > Code Analyzer Report.

    alt text

    This will open a new window displaying the MLINT results for each m-file in the current directory:

    alt text

    If you would rather automate the process using a script instead of having to click through menu options, there are a couple of submissions on the MathWorks File Exchange (here and here) that appear to work recursively on a directory structure as opposed to just a single directory.

    In additional, here is some sample code that will do what you want for a single directory:

    dirData = dir;                 %# Get data on the current directory contents
    fileIndex = ~[dirData.isdir];                 %# Get an index for the files
    fileNames = {dirData(fileIndex).name};        %# Get the file names
    [~,~,ext] = cellfun(@fileparts,fileNames,...  %# Get the file extensions
                        'UniformOutput',false);
    mFileIndex = strcmp(ext,'.m');                %# Get an index for the m-files
    cellfun(@mlint,fileNames(mFileIndex));        %# Run MLINT on each m-file
    

    You could extend the collection of file names (and paths) in this way to operate recursively on a directory tree, then run MLINT on the resulting set of files you collect.

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

Sidebar

Related Questions

I have a big, complex MATLAB program. Somewhere within that, the number 0 is
I have a complex url that in some cases results in a 403 forbiden
We have complex template classes that have some methods which will not work with
I have some complex message to show inside of a flash message so instead
We have a complex app that serves AJAX JSON streams (using ADO to grab
I have a complex RIA client that communicates with a WCF SOAP web service,
I have some complex regular expressions which I need to comment for readability and
i have complex xslt that formats xml to html now i need to be
I am looking for a way to have complex URL mappings that would depend
I have complex logical expression that look like this: ((((!((cond1) || (cond2) || (cond3))

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.