function [ output_args ] = genQMatLatex( Lf,fileName )
% Generates a latex compatible Q matrix from the matlab L (Q) matrix.

sigFigs = 3;

startStr = sprintf('%s\n%s\n%s\n','\begin{align}','\scriptsize','\matx{M} =	C\begin{bmatrix}');
endStr = sprintf('%s\n%s\n%','\end{bmatrix}','\end{align}');

LfOut = Lf.'./max(max(abs(Lf)));
[R,C] = size(LfOut);

lineStr = '';
for l=1:R    
    for k=1:C
        if (abs(real(LfOut(l,k)))<(1/(10^sigFigs)))&&(abs(imag(LfOut(l,k)))<(1/(10^sigFigs)))
            lineStrElem = '0';
        elseif (abs(real(LfOut(l,k)))>(1/(10^sigFigs)))&&(abs(imag(LfOut(l,k)))<(1/(10^sigFigs)))
            lineStrElem = num2str(real(LfOut(l,k)));
        elseif (abs(real(LfOut(l,k)))<(1/(10^sigFigs)))&&(abs(imag(LfOut(l,k)))>(1/(10^sigFigs)))
            lineStrElem = num2str(imag(LfOut(l,k)));
        else
            lineStrElem = [num2str(real(LfOut(l,k))) '+' num2str(imag(LfOut(l,k))) 'i'];
        end
        if k < C
            lineStrElem = [lineStrElem ' & '];
        else
            lineStrElem = [lineStrElem '\\'];
        end
        lineStr = [lineStr lineStrElem];
    end
    lineStr = sprintf('%s\n',lineStr);
end

fid = fopen(fileName,'wt');
fprintf(fid, '%s', [startStr lineStr endStr]);
fclose(fid);

end

