about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/SLP/misc/export_cases.m
blob: 4ab0d79022fc9b1ddf7ab72ec4edce8c3f6faa65 (plain)
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
function S = export_cases(data, names, file, misv)
% filepath = export_cases(data, names, 'filename', missing_value)
%  filename and missing_value [default [] if iscell(data) or -9999 if not] are optional
% 
% Exports BNT datasets to Netica cases (* for missing data)
%
% Written by Francois.Olivier.C.H@gmail.com
% 
% Informations could be found here http://www.norsys.com/downloads/
%
% version 80807

% inits
if nargin==1, file=['dnet' datestr(now,'-yymmdd-HHMMSS')]; end
if nargin<2, error('Variable Names needed'); end
if length(file)>5,
  if prod(double(file((end-3):end)~='.cas')), file=[file '.cas']; end
  name = file(1:end-5);
else
  name = file;
  file = [file '.cas'];
end
if nargin<4, misv=-9999; end
if iscell(data), data = bnt_to_mat(data,misv); end

[N m]=size(data);
if length(names)~=N, error('Sizes must be the same'); end

% header of the file
fid = fopen(file, 'w');
fprintf(fid, '// exported from the Bayes Net Toolbox with export_cases function \n');
fprintf(fid, '// please report bugs to francois.olivier.c.h@gmail.com\n\n');

% write names
for i=1:N
  fprintf(fid, '%s\t',names{i});
end

% exports
for l=1:m,
  fprintf(fid, '\n');
  for i=1:N,
    if data(i,l)~=misv,
      fprintf(fid, '%s',['x' num2str(data(i,l))]);
    else
      fprintf(fid, '%s','*');
    end
    if i<N, fprintf(fid, '\t'); end
  end
end

% closes file
fprintf(fid,'\n');
fclose(fid);

% outputs string
S = [pwd '/' file];