function htmlOut = matdiff(filename1, filename2)
%MATDIFF Compare similarity of two MAT-files
%   MATDIFF(filename1, filename2) brings up an HTML report showing the
%   differences between the two files.  This feature is only supported if
%   Java is available.
%
%   S = MATDIFF(...) returns the HTML report in the string S.

% Copyright 2007-2017 The MathWorks, Inc.

import comparisons.internal.util.process;
import comparisons.internal.util.APIUtils;

narginchk(2, 2);
error(javachk('jvm'));

APIUtils.parse('matdiff', filename1, filename2);
[filename1, filename2] = convertStringsToChars(filename1, filename2);

try
    if nargout == 0
        error(javachk('swing'));
        % Invoke the Comparison Tool, which will perform the comparison and
        % display the result.
        process(...
            @() comparisons_private('comparefiles',filename1,filename2)...
        );
    else
        htmlOut = process(...
            @() comparisons_private('matdiff',filename1,filename2,'')...
        );
    end
catch exception
    APIUtils.handleExceptionCallStack(exception);
end