Skip to content

Instantly share code, notes, and snippets.

@Otteri
Created October 25, 2018 12:46
Show Gist options
  • Save Otteri/93ff47ca655e97f289a3f37578ecc6fa to your computer and use it in GitHub Desktop.
Save Otteri/93ff47ca655e97f289a3f37578ecc6fa to your computer and use it in GitHub Desktop.
[Matlab] prettyPrint function for matrices and vectors
% Function pretty prints given matrix / vector
% @param M: a matrix or a vector to be printed
% @param M_name: name which is displayed in the print (optionl)
% @param precision: specify the amount of decimals to be shown (optional)
function prettyPrint(M, M_name, precision)
[rows_n, cols_n] = size(M);
% Check optional arguments
if ~exist('M_name','var'), M_name = 'PrettyPrint'; end
if ~exist('precision','var'), precision = 3; end
fprintf('%s:\n', M_name);
% Loop through the given data and print all items
for i = 1:rows_n
for j = 1:cols_n
fprintf('%12.*f ', precision, M(i, j));
end
fprintf('\n');
end
fprintf('\n');
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment