0

I am trying to create a standalone executable to be run on a windows system that will compare 2 txt files. I have been trying to do this from MATLAB. I love the way that the visdiff tool works in MATLAB, but when I compile the file using the Application compiler in MATLAB and run the program the visdiff tool does not appear. Using the visdiff tool is not necessary, but it is a nice pre-built tool.

Here is the code that I tried to use. It was created using the MATLAB 'GUIDE' tool. I then tried to compile it in MATLAB R2015b clicking the 'APPS' in the ribbon then "APPLICATION COMPILER".

function varargout = Comparator(varargin)
% COMPARATOR MATLAB code for Comparator.fig
%      COMPARATOR, by itself, creates a new COMPARATOR or raises the         existing
%      singleton*.
%
%      H = COMPARATOR returns the handle to a new COMPARATOR or the handle to
%      the existing singleton*.
%
%      COMPARATOR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in COMPARATOR.M with the given input arguments.
%
%      COMPARATOR('Property','Value',...) creates a new COMPARATOR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Comparator_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Comparator_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Comparator

% Last Modified by GUIDE v2.5 11-Dec-2015 13:20:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Comparator_OpeningFcn, ...
                   'gui_OutputFcn',  @Comparator_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Comparator is made visible.
function Comparator_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Comparator (see VARARGIN)

% Choose default command line output for Comparator
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Comparator wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Comparator_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FName, PathName, FilterIndex] = uigetfile('*.txt')
% set(hOject,'String',FName)%%%%%%%%%%CHANGE THIS!!!!!!!!!
handles.fid1=FName;
guidata(hObject,handles)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FName, PathName, FilterIndex] = uigetfile('*.txt')
% set(hOject,'String',FName)%%%%%%%%%%CHANGE THIS!!!!!!!!!
handles.fid2=FName;
guidata(hObject,handles)


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
visdiff(handles.fid1,handles.fid2)

I am also playing around creating one from scratch as follows:

clc;clear;
fid1 = fopen('t1.txt', 'r');
fid2 = fopen('t2.txt', 'r');

lines1 = textscan(fid1,'%s','delimiter','\n');
lines2 = textscan(fid2,'%s','delimiter','\n');
lines1 = lines1{1};
lines2 = lines2{1};

fclose(fid1);
fclose(fid2);

[idx1 idx2] = ismember(lines1,lines2);

Any advise about how to make the visdiff tool work in a standalone or create a new tool would be appreciated.

Nigel Davies
  • 1,640
  • 1
  • 13
  • 26
Wiggens
  • 9
  • 3
  • I'm sorry, **why** do you want to create a MATLAB deployable executable to compare files? Why can't you just use Window's built-in FC tool? – rayryeng Dec 14 '15 at 17:20
  • @Wiggens: Please put the code you used for deployment into your question, the code sample above obviously does not contain `visdiff`. Please also describe all steps you used to generate the *.exe, did you use `codegen`? – Daniel Dec 14 '15 at 17:22
  • @rayryeng: I could do it on windows, but I am even less sure about how to do what I want there. I thought the FC tool could only say "Yes they are the same," or "No they are not." I am looking for a line by line comparison denoting the differences like what the visdiff tool does. Sorry I was unclear. – Wiggens Dec 16 '15 at 04:25
  • @Daniel: I will post the code and the method in the morning. – Wiggens Dec 16 '15 at 04:34
  • @Wiggens: There is still no `visdiff` in your code, it seems to be incomplete. – Daniel Dec 17 '15 at 16:08
  • @Daniel Sorry 'comparisons_private' is the base function that 'visdiff' uses. More people are familiar with 'visdiff' so I used it in the question. You can actually interchange the two functions. I will change it in the question code, but that should not make any difference. – Wiggens Dec 18 '15 at 19:24

2 Answers2

2

I suspect visdiff falls into the category MATLAB Functions That Cannot Be Compiled, given that it brings up (or can bring up) a user interface. Generally speaking, all GUIs built into MATLAB and its toolboxes cannot be deployed with the MATLAB Compiler. To be sure, check the mccExcludedFiles.log for files that were excluded during the compilation process.

You probably need to use a "from scratch" approach, as the one you have mentioned in your question.

am304
  • 13,758
  • 2
  • 22
  • 40
  • Thank you so much. I will check the log file. Any ideas on some tips to compare the two codes? – Wiggens Dec 16 '15 at 04:27
  • The 'mccExcludedFiles.log' file looks the exact same as always. I guess that this does not mean that it is not in the file, but it is not called out specifically. – Wiggens Dec 16 '15 at 15:29
1

I have entered your program and run it from the command line and compiled. I too get this error message for the compiled version:

Undefined variable "comparisons" or class "comparisons.internal.resolvePath".
Error in comparisons_private>i_compareFiles (line 92)
Error in comparisons_private (line 22)
Error in cf>pushbutton3_Callback (line 101)

I think this is trying to tell us the compare tool is not available in compiled code.

When your code runs in MATLAB, the window it opens looks very much like the editor which this page says is not available to the compiler.

Note, I did my experiment with r2014a and r2015b and the results are the same.

I started the compiled .exe from the windows command line to see the error output.

Why don't you try winmerge instead?

Edit:

WinMerge is text only, but it you Google it, people do explain how you can use it to locate the first difference in binary files. The file size limit is >2Gytes.

UltraEdit/UltraCompare has a compare mode for binary files, as do many of the more powerful programmers text editors with a hex edit mode.

Assuming you are using Windows, if you have a bash shell such as cygwin or perhaps mingw (not git bash from the default installation) you can dump your binary files to text then use any text compare tool such as WinMerge. Search for hexdump or od. Sadly Microsoft have not added hex dump to the power shell or command window, but there are tools you could download here and here. A hex dump utility is standard on Unix/Linux.

Or you could write a MATLAB progam to dump the binary files to text in whatever format suits you best and use WinMerge to compare the text equivalents.

This question Tool for comparing 2 binary files in Windows may have better suggestions than mine.

Community
  • 1
  • 1
Nigel Davies
  • 1,640
  • 1
  • 13
  • 26
  • Thank you so much! I was unaware that if you ran through the command line that the Errors would pop out. I will have to check out winmerge. It looks extremely helpful. Do you know how it handles large files or if it can handle binary format? – Wiggens Dec 18 '15 at 19:29