与MATLAB比较文件 [英] Compare files with MATLAB

查看:364
本文介绍了与MATLAB比较文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用MATLAB比较两个文件(逐行)(* .xml, .m, .txt,...等等)。

  file1 ='toto.xml'; 
file2 ='titi.xml';

我正在寻找一个MATLAB函数(通过命令行)返回true /您可以使用MATLAB的系统命令和 fc 命令。

如果您在Windows中:

  file_name_1 ='file1.txt'; 
file_name_2 ='file2.txt';

[status,result] = system(['fc'file_name_1''file_name_2]);

如果文件相等,则状态将为0,否则为1。



对于其他操作系统,您可以使用类似的命令,如 cmp strong>在Unix而不是 fc



UPDATE:


$ b b

对于跨平台兼容性,您可以尝试以下操作:

  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)


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)

这篇关于与MATLAB比较文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆