Last change
on this file since 1 was
1,
checked in by dtax, 15 years ago
|
Dissimilarity toolbox, start!
|
File size:
1.5 KB
|
Line | |
---|
1 | % Read Bunke's data to PRTOOLS |
---|
2 | |
---|
3 | function D = prtbunke(fname) |
---|
4 | |
---|
5 | fid = fopen(fname,'r'); |
---|
6 | if fid == -1, |
---|
7 | error(['File not found: ' fname]) |
---|
8 | end |
---|
9 | |
---|
10 | ok = 0; |
---|
11 | info = []; |
---|
12 | lab = []; |
---|
13 | |
---|
14 | while ~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), |
---|
36 | D = dataset(D,lab,'featlab',lab); |
---|
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); |
---|
67 | end |
---|
68 | fclose(fid); |
---|
69 | return |
---|
Note: See
TracBrowser
for help on using the repository browser.