I would like to know how could I compare two files (line by line) (*.xml, .m,.txt,...etc) using MATLAB.
file1 = 'toto.xml';
file2 = 'titi.xml';
I'm looking for a MATLAB function (by command line) that returns me true/false or list of diff.
You can use MATLAB's system command with fc if you are in Windows:
file_name_1 = 'file1.txt';
file_name_2 = 'file2.txt';
[status,result] = system(['fc ' file_name_1 ' ' file_name_2]);
Here status will be 0 if files are equal and 1 if not. Furthermore result will have the diff result if files differ.
For other operating systems you can use similar commands such as cmp in Unix instead of fc.
UPDATE:
For cross-platform compatibility you may try the following:
file_1 = javaObject('java.io.File', 'file1.txt');
file_2 = javaObject('java.io.File', 'file2.txt');
is_equal = javaMethod('contentEquals','org.apache.commons.io.FileUtils',...
file_1, file_2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With