File size: 2,356 Bytes
796ff25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function mat2json(mat,filename)

% MAT2JSON Writes a JSON file
%
% mat2json(mat,filename)
%
% Inputs:
% mat: Matlab cell array whose entries are Matlab structures containing the
% value for each JSON field
% filename: JSON filename (.json extension)
%
% Note: using JSON2MAT followed by MAT2JSON will generally not lead back to
% the original JSON file due to the loss of digits beyond double precision
% and to the handling of trailing zeros.
%
% If you use this software in a publication, please cite:
%
% Jon Barker, Ricard Marxer, Emmanuel Vincent, and Shinji Watanabe, The
% third 'CHiME' Speech Separation and Recognition Challenge: Dataset,
% task and baselines, submitted to IEEE 2015 Automatic Speech Recognition
% and Understanding Workshop (ASRU), 2015.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2015 University of Sheffield (Jon Barker, Ricard Marxer)
%                Inria (Emmanuel Vincent)
%                Mitsubishi Electric Research Labs (Shinji Watanabe)
% This software is distributed under the terms of the GNU Public License
% version 3 (http://www.gnu.org/licenses/gpl.txt)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fid=fopen(filename,'w');
fprintf(fid,'%s\n','[');
for ind=1:length(mat), % loop over entries
    fprintf(fid,'    %s\n','{'); % entry delimiter
    fields=fieldnames(mat{ind});
    for f=1:length(fields), % loop over fields
        field=fields{f};
        value=mat{ind}.(field);
        if ischar(value), % text field
            fprintf(fid,'        "%s": "%s"',field,value);
        elseif islogical(value), % boolean field
            if value,
                fprintf(fid,'        "%s": true',field);
            else
                fprintf(fid,'        "%s": false',field);
            end
        elseif value==floor(value), % integer field
            fprintf(fid,'        "%s": %d',field,value);
        else % double field
            fprintf(fid,'        "%s": %17.*f',field,15-max(0,floor(log10(value))),value);
        end
        if f~=length(fields), % field delimiter
            fprintf(fid,', ');
        end
        fprintf(fid,'\n');
    end
    fprintf(fid,'    }'); % entry delimiter
    if ind~=length(mat),
        fprintf(fid,', ');
    end
    fprintf(fid,'\n');
end
fprintf(fid,']');
fclose(fid);

return