function str=tabmsd(M,S,s);
%TABMSD creates a table of the form:
%
%            -----------------------------------------------------
%            |   M(1,1)   |   M(1,2)   |   M(1,3)   |   M(1,4)   | 
%            |  (S(1,1))  |  (S(1,2))  |  (S(1,3))  |  (S(1,4))  |
%            ----------------------------------------------------- ...
%            |   M(2,1)   |   M(2,2)   |   M(2,3)   |   M(2,4)   | 
%            |  (S(2,1))  |  (S(2,2))  |  (S(2,3))  |  (S(2,4))  |
%            -----------------------------------------------------
%            |   M(3,1)   |   M(3,2)   |   M(3,3)   |   M(3,4)   | ...
%            |  (S(3,1))  |  (S(3,2))  |  (S(3,3))  |  (S(3,4))  |
%            -----------------------------------------------------
%               :                    :                     :
%
%  INPUTS: 
%    (i) M = mxn matrix for table  (e.g. means of estimates)
%   (ii) S = mxn matrix for elements in ( ) in table (e.g. standard errors)
%  (iii) s = number of spaces padding the number in the table (which has
%            converted to a 10-space string)
%
%  OUTPUTS: str= a string matrix giving the table of the form above.
%
estr='The mean and standard deviation matrices must have the same dimension.';
if size(M)~=size(S); 
  error(estr);
end;
[r,c]=size(M);
p=2*s+12;
pad1=' ';
for i=1:s-1;
  pad1=[pad1,' '];
end;
for i=1:r;
  for j=1:c;
    pad2=' ';
    pad3=' ';
    snum1=num2str(M(i,j));
    snum2=num2str(S(i,j));
    if length(snum1)<11; 
      for k=1:s+11-length(snum1)-1;
        pad2=[pad2,' '];
      end;
    else;
      pad2=pad1;
    end;
    if length(snum2)<10;
      for k=1:s+10-length(snum2)-1;
        pad3=[pad3,' '];
      end;
    else;
      pad3=pad1;
    end;
    str1(i,(j-1)*p+1:j*p)=[pad2,snum1,' ',pad1];
    str2(i,(j-1)*p+1:j*p)=[pad3,'(',snum2,')',pad1];
  end;
end;
[row,col]=size(str1);
space=' ';
for i=1:col-1;
  space=[space,' '];
end;
for i=1:r;
  str(3*i-2,:)=str1(i,:);
  str(3*i-1,:)=str2(i,:);
  str(3*i,:)=space;
end;
