Mercurial > octave-nkf
comparison scripts/general/int2str.m @ 4878:4eaf35cfdb11
[project @ 2004-04-23 15:42:10 by jwe]
author | jwe |
---|---|
date | Fri, 23 Apr 2004 15:42:10 +0000 |
parents | a9560cebae6e |
children | c08cb1098afc |
comparison
equal
deleted
inserted
replaced
4877:0ab4fd8ded30 | 4878:4eaf35cfdb11 |
---|---|
30 ## Author: jwe | 30 ## Author: jwe |
31 | 31 |
32 function retval = int2str (x) | 32 function retval = int2str (x) |
33 | 33 |
34 if (nargin == 1) | 34 if (nargin == 1) |
35 x = round (x); | 35 x = round (real(x)); |
36 sz = size(x); | |
37 nd = ndims (x); | |
36 nc = columns (x); | 38 nc = columns (x); |
37 if (nc > 1) | 39 if (nc > 1) |
38 ifmt = get_fmt (x(:,1), 0); | 40 idx = cell (); |
39 rfmt = get_fmt (x(:,2:end), 2); | 41 for i = 1:nd |
42 idx {i} = 1:sz(i); | |
43 endfor | |
44 idx(2) = 1; | |
45 ifmt = get_fmt (x(idx{:}), 0); | |
46 idx(2) = 2:sz(2); | |
47 rfmt = get_fmt (x(idx{:}), 2); | |
40 fmt = strcat (ifmt, repmat (rfmt, 1, nc-1), "\n") | 48 fmt = strcat (ifmt, repmat (rfmt, 1, nc-1), "\n") |
41 else | 49 else |
42 fmt = strcat (get_fmt (x, 0), "\n"); | 50 fmt = strcat (get_fmt (x, 0), "\n"); |
43 endif | 51 endif |
44 tmp = sprintf (fmt, round (x.')); | 52 tmp = sprintf (fmt, permute (x, [2, 1, 3 : nd])); |
45 tmp(end) = ""; | 53 tmp(end) = ""; |
46 retval = split (tmp, "\n"); | 54 retval = split (tmp, "\n"); |
47 else | 55 else |
48 usage ("int2str (x)"); | 56 usage ("int2str (x)"); |
49 endif | 57 endif |