File Exchange

image thumbnail

Compare two .mat files

version (16.8 KB) by Xianyao Chen
Compare two .mat files and display the contents and difference of mat files.


Updated 10 Jun 2004

No License

Compare two mat files,

useage: matc matfile1.mat matfile2.mat

it will show three different releationship between the variables stored in mat file:

not exist, not equal, equal.

Although one can use
A = load matfile1;
B = load matfile2;
to determine if two mat files are exactly same, it can not help one determine which variable in matfile1 is different or does not exist in matfile2.


matc aa.mat bb.mat
Source File: aa.mat --- Target File: bb.mat
Variable :: a || not exist
Variable :: b || equal
Variable :: c || not equal

Source File: bb.mat --- Target File: aa.mat
Variable :: ab || not exist
Variable :: b || equal
Variable :: c || not equal

Cite As

Xianyao Chen (2021). Compare two .mat files (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

Naveen Reddy

Error: matc.p was generated prior to MATLAB version 7.5 (R2007b) and is no longer supported. Use pcode to regenerate the
file using MATLAB R2007b or later.
Can some one suggest how to resolve

João Morais


Dejan Vujatovic

jorge Perez


I had tons of trouble with this, it even appeared to mess up my search path. I switched to using the one by Michael Arant instead which worked right out of the box.

Samuel Maliva

Very helpful

Please can I get the test function to compare aa.mat and bb.mat


Very useful !
It's easy to use and helps a lot.

Jochen Rau

Very useful. Thanks!
Another nice extension would be to integrate sth like submission #22752 (recursive comparison of structures) if a variable is a structure.


Excellent, thank you!


good one

HOng T


Dadi Gudmundsson

Simple, effective, useful.

Helps Alot

Thank you so much

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!