NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/matutil/mat2str.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function s = mat2str(x)
2
3 % MAT2STR String equivalent to a matrix.
4 %  MAT2STR(X) converts matrix X to a one-line
5 %   string which is roughly equivalent
6 %   to X, for display purposes.  If X is
7 %   larger than a scalar, then its values are
8 %   written between square brackets.
9
10 % Copyright (C) 1991 Charles R. Denham, Zydeco.
11
12 if nargin < 1
13    help mat2str
14    x = [1 2 3; pi inf nan];
15    disp(' The matrix:'), disp(' ')
16    disp(x), disp(' becomes the string:'), disp(' ')
17    disp([' ' mat2str(x)])
18    return
19 end
20
21 quote = '''';
22
23 [m, n] = size(x);
24
25 s = '';
26 bracket = isstr(x) & m > 1 | ~isstr(x) & length(x) > 1;
27 if bracket, s = ['[']; end
28
29 for i = 1:m
30    if isstr(x)
31       t = [quote x(i, :) quote];
32       s = [s t];
33      else
34       for j = 1:n
35          z = x(i, j);
36          if isnan(z)
37             t = 'nan';
38            elseif z == inf
39             t = 'inf';
40            elseif z == -inf
41             t = '-inf';
42            elseif z == fix(z)
43             t = int2str(z);
44            else
45             t = num2str(z);
46          end
47          s = [s t];
48          if j < n, s = [s ' ']; end
49       end
50    end
51    if i < m, s = [s '; ']; end
52 end
53
54 if bracket, s = [s ']']; end
Note: See TracBrowser for help on using the browser.