LTPDA_MAT2STR overloads the mat2str operator to set the precision at a central place. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: LTPDA_MAT2STR overloads the mat2str operator to set the precision at a central place. CALL: str = ltpda_mat2str(number); str = ltpda_mat2str(matrix); VERSION: $Id: ltpda_mat2str.m,v 1.5 2008/02/19 17:28:38 ingo Exp $ HISTORY: 26-07-2007 Diepholz Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function str = ltpda_mat2str(number) 0002 % LTPDA_MAT2STR overloads the mat2str operator to set the precision at a central place. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: LTPDA_MAT2STR overloads the mat2str operator to set the 0007 % precision at a central place. 0008 % 0009 % CALL: str = ltpda_mat2str(number); 0010 % str = ltpda_mat2str(matrix); 0011 % 0012 % VERSION: $Id: ltpda_mat2str.m,v 1.5 2008/02/19 17:28:38 ingo Exp $ 0013 % 0014 % HISTORY: 26-07-2007 Diepholz 0015 % Creation 0016 % 0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0018 0019 MAX_PRECISION = 20; 0020 0021 s = size(number); 0022 if s(1) ~= 1 && s(2) ~= 1 0023 str = mat2str(number, MAX_PRECISION); 0024 0025 elseif isreal(number) 0026 0027 % For vectors it is faster to use sprintf directly 0028 if s(1) ~= s(2) 0029 str = '['; 0030 else 0031 str = ''; 0032 end 0033 if s(1) > s(2) 0034 str = [str sprintf('%.17g;', number)]; 0035 else 0036 str = [str sprintf('%.17g ', number)]; 0037 end 0038 if s(1) ~= s(2) 0039 str = [str(1:end-1) ']']; 0040 else 0041 str = str(1:end-1); 0042 end 0043 0044 else 0045 str = mat2str(number, MAX_PRECISION); 0046 end 0047 0048 0049