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.4 2007/10/26 14:57:36 hewitson 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.4 2007/10/26 14:57:36 hewitson 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 else 0025 0026 % For vectors it is faster to use sprintf directly 0027 if s(1) ~= s(2) 0028 str = '['; 0029 else 0030 str = ''; 0031 end 0032 if s(1) > s(2) 0033 str = [str sprintf('%.17g;', number)]; 0034 else 0035 str = [str sprintf('%.17g ', number)]; 0036 end 0037 if s(1) ~= s(2) 0038 str = [str(1:end-1) ']']; 0039 else 0040 str = str(1:end-1); 0041 end 0042 end 0043 0044 0045