function CR(A,B)
% Calculates the compression ratio between matrix A and matrix B.
% Matrix A should be original matrix and matrix B the compressed matrix.
%
% To use this function type `CR(A,B)`.

m1 = size(A,1);
n1 = size(A,2);
m2 = size(B,1);
n2 = size(B,2);
nonzerosA = 0;
nonzerosB = 0;
CR = 0;

if or((m1 ~= m2),(n1 ~= n2))
    disp 'Matrix dimensions do not match!'
    return;
end

for i = 1:n1
    for j = 1:m1
        if (A(i,j) ~= 0)
            nonzerosA = nonzerosA + 1;
        end
        if (B(i,j) ~= 0)
            nonzerosB = nonzerosB + 1;
        end
    end
end

CR = nonzerosA/nonzerosB