A=testmatrix('magi',3) /// \sleftarrow{{\normalfont a \verb+3x3+ magic square}} [ma,na]=size(A); /// \sleftarrow{{\normalfont size of the string matrix}} B=string(A) /// \sleftarrow{{\normalfont from scalar matrix to string matrix}} delim='\BS\BS'; B=[B,delim(ones(ma,1))]; /// \sleftarrow{{\normalfont adding a column}} ///{\normalfont note that \verb+delim(ones(ma,1))+ builds a \verb+(ma,1)+ with string \verb+delim+ in each row} B=strcat(B',' & ') /// \sleftarrow{{\normalfont transpose and concatenate with a separator}} B=strsubst(B,'& \BS\BS &','\BS\BS') /// \sleftarrow{{\normalfont substitutions }} B=strsubst(B,'& \BS\BS','') /// \sleftarrow{{\normalfont \verb+B+ is now a string}} delim="c";delim=strcat(delim(ones(na,1))) /// \sleftarrow{{\normalfont builds a repeated pattern (\verb+na+ times)}} text=['\BS[ A= {\BS}begin\{array\}\{'+delim+'\}'; B; '{\BS}end\{array\} \BS]' ]; /// \sleftarrow{{\normalfont concatenate matrix }} mputl(text,'matrix.tex') /// \sleftarrow{{\normalfont a string matrix as text output in a file \verb+matrix.tex+}} B=string(A);/// \sleftarrow{{\normalfont another way to build \verb+B+ } } fmt='%d'; fmt = strcat(fmt(ones(1,na)),' &') + '{\BS}n'; /// \sleftarrow{{\normalfont building a format}} B= msprintf(fmt,A) /// \sleftarrow{{\normalfont builds a string vector using formatted output}} B=string(A);/// \sleftarrow{{\normalfont again an other way to build \verb+B+}} B=strcat(B,' & ','c'); /// \sleftarrow{{\normalfont concatenate \verb+B+ columns with an added separator}} text= ['\BS[ A= {\BS}begin\{array\}\{'+delim+'\}'; B + ' \BS\BS' ; /// \sleftarrow{{\normalfont \verb+B+ is a column vector, we concatenate each row with ' \BS\BS' }} '{\BS}end\{array\} \BS]' ] /// \sleftarrow{{\normalfont matricial concatenation using ``\verb-+-''}} text=strsubst(text,'{\BS}','\');/// @@prerequisite text=strsubst(text,'\{','{'); /// @@prerequisite text=strsubst(text,'\}','}'); /// @@prerequisite mputl(text,'matrix.tex') /// @@prerequisite