Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Inside the MATLAB Desktop

May 5th, 2008

File and Folder Comparison Tool Update in R2008a


I’d like to welcome guest blogger Malcolm Wood from the Simulink Model Management team. Malcolm will occasionally be blogging here on the Inside the MATLAB Desktop blog.

For many years the MATLAB Desktop has included a simple tool for comparing text files. You may have used it from the MATLAB Editor to see the changes you have made to your M-file since you last saved it, or you may have used it from the Directory Browser to compare two files on disk.

In R2008a we extended the capabilities of this tool to compare files which aren’t just plain text. You can now use it to compare the variables in MAT-files. It will tell you the names of the variables which are in each file, and for the variables which appear in both files it will tell you whether their values are the same or not:

And if you want to see exactly what’s different about these two variables called “X”, then clicking on either one will open it in the Variable Editor so that you can take a closer look.

For other types of binary file, the MATLAB will scan the two files and simply tell you whether their contents are the same or not.

You might have noticed from the screenshot above that the title is “File and Directory Comparisons”, namely because another new feature is the ability to compare entire directories. We think this sort of thing is useful for cases where you’ve taken a copy of some files and made some changes to get them to work for you. By comparing the two directories you can quickly review all the changes you made without leaving MATLAB.

This tool is available from the Directory Browser: just right-click on a directory and choose “Compare Against…”.

If the two directories you compare contain files of the same name, MATLAB will scan those files to determine whether their contents are the same or not. If they’re not, you’ll see a hyperlink to compare the files in detail.

If there are sub-directories with the same name but different time-stamps, there will be a hyperlink to let you compare the contents of those too.

We hope you’ll find these new features useful. And if there are changes you think we should make, leave us a comment to let us know!


-by Malcolm Wood, The MathWorks

12 Responses to “File and Folder Comparison Tool Update in R2008a”

  1. Marcelo replied on :

    I would suggest a better user interface, just like in the TotalCommander file manager, where you can compare by content and also easily select what kind of synchronization should be made.

  2. Daniel Armyr replied on :

    Hi.
    Is it just me, or will we very soon se an integrated CVS/SVN client in matlab? I personally use version controll for all projects, even the very small ones. I have to admit, though, that as nice as these new features are, they can’t even compare to a proper version control system.

  3. Tim Davis replied on :

    Beautiful, just beautiful. Worthy of a poetic thanks:

    I came upon a source code dark,
    and wondered where I left my mark,
    with my edits just for a lark,
       and forgot just where
    I changed it; now my mind is stark,
       and mem'ry bare.
    
    But then in MATLAB oh-8a
    the file compare has saved the day
    and giv'n reason now to say
       a heartfelt thanks;
    It sheds a light and brilliant ray
       on code, I thinks!
    
  4. Mike replied on :

    Marcelo,

    Thank you for the feedback, we will take that under consideration.

    Daniel,

    MATLAB does provide source control integration. Take a look at the documentation page for that: Source Control Interface.

    Tim,

    creative poems
    provide great feedback for us
    we work hard for you

  5. Tim Davis replied on :

    Is there a way to ignore variations in white space? Can comments be ignored? That way, if I put a block of code inside an “if”, and indent it properly, not all of the code will be flagged as different. These would be useful options if you want to look at core code differences and ignore syntactical massaging.

  6. Mike replied on :

    Tim,

    The comparison is just a simple text diff. It would be neat if there was a syntax-aware mode. I’ll pass that along to the developer. Thanks.

  7. Tim Davis replied on :

    p.s. In case the reader missed the allusion … “I came upon a source code dark” is an allusion to Dante’s Inferno, the first 3 lines of which are:

    Midway upon the journey of our life
      I found myself within a forest dark,
      For the straightforward pathway had been lost.
    

    Also … a low rank update to the poem above. The line

    with my edits just for a lark,
    

    would sound better as:

    with edits made just for a lark,
    

    Keep up the hard work! :-)

  8. Georg Wiedermann replied on :

    Dear Malcolm,

    are there any plans in the pipeline to provide the missing Simulink model comparison tool?

    Best Regards

    Georg

  9. Han Geerligs replied on :

    Hello Ken/Malcolm,

    I found that when comparing files with itself (so binary identical) however differences are found.
    The contents of that specific file are all Simulink.Parameter data objects. When using “ordinary” scalars of vectors the problem doesnt exist and the variables are marked as identical by the compare tool.

    Are you aware of such an issue?

    kind regards, Han

  10. Malcolm Wood replied on :

    Han,

    The MAT-file differencing mechanism uses the MATLAB “==” operator, but for Simulink.Parameter objects this operator asks “are these the same object?”, which is not the right question. For example:

    >> x1 = Simulink.Parameter
    >> x2 = Simulink.Parameter
    >> x1==x2

    ans =

    0

    For these objects, it turns out that the “isContentEqual” method is the right one to use:

    >> isContentEqual(x1,x2)

    ans =

    1

    But that’s probably not true for other types of object. Java programmers will be familiar with this sort of problem. I’ll look into whether there’s a general solution to it here.

    Malcolm

  11. Anand replied on :

    Is there any tool (either matlab/third party) that compares two matlab models and give graphaic view of the diffrence? I am talking about model .mdl file

  12. Mike replied on :

    That’s a great idea.

Leave a Reply


Inside the MATLAB Desktop is written by the MATLAB Interface teams.

Team picture
  • Mike: @Daniel, What are the keyboard shortcuts you use most often? What operations do wish there were shortcuts for?
  • Biswanath Senapati: I am using MATLAB tool for our work. Now I want to integrate matlab desktop (command window) in...
  • Ken: Hi John, I can appreciate your desire for a true Mac user interface. As a Mac user myself, I am constantly...
  • John Haitas: 7 years on… still no native graphics for the Mac. When will Mathworks take time to code a GUI...
  • Ken: Hi Daniel, Your absolutely right - keyboard shortcuts in MATLAB is an area that could use some improvement. Good...
  • Daniel Armyr: Hi. I am one of those old-school people who feels that the command-line has definate merit. However,...
  • Mike: Thanks. Let us know what kinds of things you find most useful.
  • Cnenf: Thank you Michael! MATLAB and this blog has proven itself to be simply invaluable in nearly every project we...
  • Jiro: Yes, if you search the File Exchange, you’ll find SWAP, which was inspired by the file featured here:...
  • Mike: Quan, Excellent suggestion. You probably tried this, but don’t forget about searching the MATLAB File...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics