Skip to content

Instantly share code, notes, and snippets.

@LemonPi
Created November 6, 2019 01:03
Show Gist options
  • Save LemonPi/56c12bb7433bfcb91b6a29a21f2bed6b to your computer and use it in GitHub Desktop.
Save LemonPi/56c12bb7433bfcb91b6a29a21f2bed6b to your computer and use it in GitHub Desktop.
print matrix/vector in matlab in latex form
function code = bmatrix(X)
code = "\\begin{bmatrix}" + newline;
rows = size(X, 1);
cols = size(X, 2);
for i=1:rows
for j=1:cols
if j == cols
code = code + X(i, j) + " \\\\";
else
code = code + X(i, j) + " & ";
end
end
code = code + newline;
end
code = code + "\\end{bmatrix}" + newline;
fprintf(code);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment