source: distools/prtbunke.m @ 111

Last change on this file since 111 was 79, checked in by bduin, 11 years ago
File size: 1.5 KB
RevLine 
[10]1% Read Bunke's data to PRTOOLS
2
3function D = prtbunke(fname)
4
5fid = fopen(fname,'r');
6if fid == -1,
7  error(['File not found: ' fname])
8end
9
10ok   = 0;
11info = [];
12lab  = [];
13
14while ~ok,
15  str = fgetl(fid);
16  switch str
17    case '.CHARACTERBAND TYPE'
18      info.datatype = fgets(fid);
19
20    case '.COST FUNCTION'
21      str = fgets(fid);
22      [info.costfun,info.cost] = strread(str,'%s%f','delimiter',' ');
23
24    case '.CLASS MEMBERSHIP'    % here come labels
25      str = fgets(fid);
26      lab = strread(str,'%s','delimiter',' ');
27
28    case '.DISTANCE MATRIX'
29      D = fscanf(fid,'%f');
30      N = sqrt(length(D));
31      D = reshape(D,N,N);
32      if issym(D,1e-10),
33        D = 0.5*(D+D');
34      end
35      if ~isempty(lab),
[79]36        D = prdataset(D,lab,'featlab',lab);
[10]37        C = classsizes(D);
38        % Should it be class frequencies or equal priors?
39        if length(C) > 1,
40          D = setprior(D,C/sum(C));
41        end
42        if ~isempty(info),
43          D = setuser(D,info);
44        end
45        p   = findstr(lower(fname),'_norm');
46        if ~isempty(p),
47          pos = findstr(lower(fname),'/');  % Linux
48          if isempty(pos)
49            pos = findstr(lower(fname),'\');  % Windows
50          end
51          if isempty(pos),
52            z = 1;
53          else
54            I = find(pos < p(1));
55            z = pos(I(end))+1;
56          end
57          D = setname(D,['Distance matrix for ' fname(z:p(1)-1)]);
58        else
59          D = setname(D,'Distance matrix');
60        end
61      end
62      ok = 1;
63    otherwise
64        ;
65  end
66  ok = feof(fid);
67end
68fclose(fid);
69return
Note: See TracBrowser for help on using the repository browser.