matrix2str.m

来自「hard disk drive servo control tools, it 」· M 代码 · 共 28 行

M
28
字号
function outstr = matrix2str(matrix0)
%
%   This function converts a matrix into a string
%   Its dual function : evalin('base', str)
%    
%    
outstr='[';
[nrows,ncols]=size(matrix0);
for N=1:nrows,
   outstr=[outstr,  term2str(matrix0(N,1)) ];
   for P=2:ncols,
      outstr=[outstr,  ', ', term2str(matrix0(N,P)) ];
   end 
   if N<nrows,  outstr=[outstr, '; '];        end     
end
outstr=strcat(outstr, ']');
        
if nrows<=1 & ncols<=1
   outstr=term2str(matrix0);
end   

% in case the element of the matrix is symbolic expression
function outstr = term2str(term)
if isnumeric(term) 
    outstr=num2str(term,'%0.6g');
else
    outstr=char(term);
end    

⌨️ 快捷键说明

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