mat2table.m

来自「JLAB is a set of Matlab functions I have」· M 代码 · 共 44 行

M
44
字号
function[str]=mat2table(x,prec)%MAT2TABLE Converts a matrix of numbers into a LaTeX-style table.%%   STR=MAT2TABLE(MAT,PREC) converts a matrix of numbers into a string%   matrix.  Columns of MAT are separated with ' & ' and the last%   column in STR is followed by ' \\'.  This allows matrices to be%   converted into a form that can be easily pasted into a LaTeX%   document.%%   PREC specifies the precision of the last retained digit. For%   example, PREC = -2 specifies that the hundredths digit is to be%   retained, and so on.  PREC may either be a scalar, or an array%   indicating the precision to use for each column of MAT.%%   See also VINDEX, DIGIT%   _________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information%   (C) 1999, 2004 J.M. Lilly --- type 'help jlab_license' for details        if nargin==1   prec=0;endif length(prec)==1	prec=prec*[1+0*x(1,:)];end%put a \\ at end of all rowsstr=char(real('\')*[1+0*x(:,1)]);str=[str str];%work backwardsandv=char(real('&')*[1+0*x(:,1)]);blankv=char(real(' ')*[1+0*x(:,1)]);for i=size(x,2):-1:1	if i==size(x,2)	     	str=[vnum2str(x(:,i),prec(i),'spaces') blankv str];	else		str=[vnum2str(x(:,i),prec(i),'spaces') blankv andv blankv str];	endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?