Created
January 2, 2018 17:39
-
-
Save tpaschalis/841dd4a57434ea34506c4408b13547c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.