% MATRIX2TEX(MATRIX,PLACES) returns the LaTeX-formatted matrix % % MATRIX is the polynomial defined in matlab/octave form. % Format is a string representing the fprint format % %d Decimal notation (e.g. integer) % %e Exponential notation (% in 3.1415e+00) % %E Exponential notation (using an uppercase E as in 3.1415E+00) % %f Fixed-point notation % %g The more compact of %e or %f. Insignificant zeros do not print, sorry. % %G Same as %g, but using an uppercase E % etc. See C reference for more information. % Numbers (two number to be exact, with a decimal between them) can be injected between % the '%' and the letter, as per a C reference of your choice. % Default format is '%5.3f'; % % Example: % a=rand(4,2); % matrix2tex(a) % matrix2tex(a,'%8.3g') % a=a*1000; % matrix2tex(a,'%8.3e') % Copyright Joseph C. Slater, 2005 % % Modified 06-11-2006 by Brendan C. Wood -- Synchroverge % (bug-fix, clipboard copy function, and string return) function texstr_final = matrix2tex(a,format) texstr=''; m=size(a,1); n=size(a,2); if nargin==1 format='%5.3f'; end eol='\\\\'; formataug=[format '&']; for i=1:m-1 texstr=[texstr sprintf(formataug,a(i,1:(n-1))) sprintf(format,a(i,n)) eol ' \n']; end texstr=[texstr sprintf(formataug,a(m,1:(n-1))) sprintf(format,a(m,n)) ' \n']; texstr_final = sprintf(texstr); % if exist('ver')==2 % sprintf(texstr) % else % fprintf(texstr) % end clipboard('copy',texstr_final)