%% Function htmltrix( M ) 
%%
%% By: Michael K. Pellegrino
%%
%% input: any KxN matrix
%% output: a string formatted in HTML
%%         of the matrix
%%

function [ret] = htmltrix ( M )
  format rat;
  [nrow,ncol]=size( M );
  x="";
  v=1;
  x = strcat( x, "<table border=1><tr><td align=center>" );
  for i=1:nrow
    for j=1:ncol
      v++;
      x= strcat( x, num2str(M(i,j)) );
      if(( j == ncol ) && ( i == nrow ))
	x=strcat( x, "</td></tr></table>");
      else if(( j == ncol ) && ( i != nrow ))
	  x=strcat( x, "</td></tr><tr><td align=center>");
	else if(( j != ncol ) && ( v !=(nrow*ncol+1) ))
	    x=strcat( x, "</td><td align=center>");
	  endif
	endif
      endif
    endfor
  endfor
  ret=x;
endfunction
