To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / utilities / UTIL_showStruct.m @ 33:161913b595ae

History | View | Annotate | Download (2.11 KB)

1
function UTIL_showStruct(structure, name, valuesOnly, terminator)
2
% showStruct prints out the values in a single structure
3
% using the format <name> '.' <fieled> ' = ' <value><terminator>
4
% e.g. 
5
% showStruct(params,'params')         % standard usage
6
%showStruct(params,'params', 0, ';')  % adds final comma
7
%showStruct(params,'params', 1)      % omits structure and field names
8

    
9
if nargin<3, valuesOnly=0; end
10
if nargin<4, terminator=[]; end
11

    
12
fields=fieldnames(eval('structure'));
13
for i=1:length(fields)
14
    % y is the contents of this field
15
    y=eval([ 'structure.' fields{i}]);
16
    if ischar(y),
17
        % strings
18
        if valuesOnly
19
            fprintf('\n%s', y)
20
        else
21
            fprintf('\n%s.%s=\t''%s%s''', name, fields{i},y,terminator)
22
        end
23
    elseif isnumeric(y)
24
        % arrays
25
        if length(y)>1
26
            % matrices and vectors
27
            [r c]=size(y);
28
            if r>c, y=y'; end   % make row vector from column vector
29
            [r c]=size(y);
30
            
31
            if r>10
32
                % large matrix
33
                fprintf('\n%s.%s=\t%g x %g matrix',name, fields{i}, r, c)
34
                
35
            elseif r>1
36
                % small matrix
37
                for row=1:r
38
                    fprintf('\n%s.%s(%1.0f)=\t%s;', name, fields{i},row, num2str(y(row,:)))
39
                end
40
                
41
            elseif c>20
42
                % long row vector
43
                fprintf('\n%s.%s=\t %g...   [%g element array]%s',name, fields{i}, y(1),c, terminator)
44
                
45
            else
46
                fprintf('\n%s.%s=\t[%s]%s', name, fields{i},num2str(y),terminator)
47
            end
48
        else
49
            % single valued arrays
50
            if valuesOnly
51
                fprintf('\n%s%s', num2str(y), terminator)
52
            else
53
                fprintf('\n%s.%s=\t%s%s', name, fields{i},num2str(y), terminator)
54
            end
55

    
56
        end % length (y)
57
    elseif iscell(y)
58
        fprintf('\n%s.%s=\t cell array', name, fields{i})
59
            
60
    elseif isstruct(y)
61
        fprintf('\n%s.%s=\t structure', name, fields{i})
62
    end     % isstr/ numeric
63

    
64
end         % field
65
fprintf('\n')