comparison m-toolbox/classes/+utils/@helper/mat2str.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % MAT2STR overloads the mat2str operator to set the precision at a central place.
2 %
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %
5 % DESCRIPTION: MAT2STR overloads the mat2str operator to set the
6 % precision at a central place.
7 %
8 % CALL: str = mat2str(number);
9 % str = mat2str(matrix);
10 %
11 % VERSION: $Id: mat2str.m,v 1.4 2011/04/05 12:51:45 mauro Exp $
12 %
13 % HISTORY: 26-07-2007 Diepholz
14 % Creation
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17 function str = mat2str(number)
18
19 if isempty(number)
20 str = '[]';
21 return
22 end
23
24 if isvector(number) && isreal(number)
25 s = size(number);
26 % For vectors it is faster to use sprintf directly
27 if s(1) ~= s(2)
28 str = '[';
29 else
30 str = '';
31 end
32 if s(1) > s(2)
33 str = [str sprintf('%.17g;', number)];
34 else
35 str = [str sprintf('%.17g ', number)];
36 end
37 if s(1) ~= s(2)
38 str = [str(1:end-1) ']'];
39 else
40 str = str(1:end-1);
41 end
42
43 else
44 str = mat2str(number, 20);
45 end
46
47 end
48