Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function mat2lat(A)
filename = 'tabular.tex';
fileID = fopen(filename, 'w+');
[rows, cols] = size(A);
% Change alignment of your output with the following character
tabalign = repmat('c', 1, cols);
fprintf(fileID,'\\begin{table}[h] \n');
fprintf(fileID,'\\centering \n');
fprintf(fileID,'\\begin{tabular}{%s} \n', tabalign);
% Change formatting of your output with the following line
tabformat = repmat('%.2f & \t', 1, cols); % Define output format
tabformat = tabformat(1:end-4); % Remove last '&' char
tabformat = [tabformat ' \\\\ \n']; % Add newlines
fprintf(fileID, tabformat, A); % Spit out input matrix
fprintf(fileID,'\\end{tabular}\n');
fprintf(fileID,'\\end{table}\n');
fclose(fileID);
fprintf('Done :)\n');
end
@tpaschalis

This comment has been minimized.

Copy link
Owner Author

tpaschalis commented Jan 2, 2018

Simple function to convert a Matlab matrix to a LaTeX table/tabular environment. Just mat2lat(A) your matrix, copy/paste to your own .tex file, and compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.