No BSD License  

Highlights from
Generate Arrays

Generate Arrays

by

 

25 May 2008 (Updated )

Converts a Matlab array to C and LaTeX

generate_LaTeX_array(a, name, format)
function str = generate_LaTeX_array(a, name, format)

% str = generate_LaTeX_array(a, name, format)
%
% DESC:
% generates a LaTeX array. Use fprintf(str) to generate a matlab output that
% can be copied in your LaTeX document.
%
% AUTHOR
% Marco Zuliani - zuliani@ece.ucsb.edu
%
% VERSION:
% 1.0.0
%
% INPUT:
% a             = array
% name          = array name
% format        = format specifier
%
% OUTPUT:
% str           = LaTeX instructions

% HISTORY:
% 1.0.0         - May 24, 2008 - initial version

% input parameters
if (nargin < 2)
    name = inputname(1);
end;

if (nargin < 3)
    format = '%3.3f';
end;    

str = ['\n' name '=\n\\left['];
str = [str '\n\\begin{array}{' repmat('c', 1, size(a, 1) ) '}\n' ];
for m = 1:size(a, 1)-1

    for n = 1:size(a, 2)-1
        str = [str, sprintf(' %s &', num2str(a(m,n), format))];
    end;
    str = [str, sprintf(' %s \\\\ \\n', num2str(a(m,n+1), format))];
    
end;

for n = 1:size(a, 2)-1

    str = [str, sprintf(' %s &', num2str(a(m+1,n), format))];

end;
str = [str, sprintf(' %s', num2str(a(m+1,n+1), format))];

str = [str '\n\\end{array}\n\\right]\n'];

return

Contact us