Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_label2num.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [nos,names] = som_label2num(L) | |
2 | |
3 %SOM_LABEL2NUM Recodes textual data labels to interger class labels | |
4 % | |
5 % [class,names]=class2num(L) | |
6 % | |
7 % [class,names]=class2num(sData) | |
8 % [class,names]=class2num(sMap) | |
9 % [class,names]=class2num(sData.labels); | |
10 % | |
11 % Input and output arguments ([]'s are optional): | |
12 % | |
13 % L (map struct, data struct, | |
14 % Nx1 cell array of strings, | |
15 % a Nxn char array) textual labels | |
16 % class (vector) Nx1 vector of integers where N is the number of original text labels | |
17 % names (cell) kx1 array of strings where names(i) correspons to integer label i | |
18 % | |
19 % See also KNN | |
20 | |
21 % Contributed to SOM Toolbox 2.0, October 29th, 2000 by Johan Himberg | |
22 % Copyright (c) by Johan Himberg | |
23 % http://www.cis.hut.fi/projects/somtoolbox/ | |
24 | |
25 % Version 2.0beta Johan 291000 | |
26 | |
27 %% Init %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
28 | |
29 if isstruct(L); | |
30 if isfield(L,'type') & ischar(L.type), | |
31 ; | |
32 else | |
33 error('Invalid map/data struct?'); | |
34 end | |
35 switch L.type | |
36 case {'som_map', 'som_data'} | |
37 class=L.labels(:,1); | |
38 otherwise error('Invalid map/data struct?'); | |
39 end | |
40 elseif vis_valuetype(L,{'cellcolumn_of_char'}), | |
41 class=L; | |
42 elseif vis_valuetype(L,{'chararray'}), | |
43 class=cellstr(L); | |
44 else | |
45 error('Input must be an Nx1 cell array of strings, a char array, a map struct or a data struct.'); | |
46 end | |
47 | |
48 names = {}; | |
49 nos = zeros(length(class),1); | |
50 for i=1:length(class), | |
51 if ~isempty(class{i}) & ~any(strcmp(class{i},names)), | |
52 names=cat(1,names,class(i)); | |
53 end | |
54 end | |
55 | |
56 tmp_nos = (1:length(names))'; | |
57 for i=1:length(class), | |
58 if ~isempty(class{i}), | |
59 nos(i,1) = find(strcmp(class{i},names)); | |
60 end | |
61 end | |
62 | |
63 if any(nos==0), | |
64 nos=nos+1; | |
65 names(2:end+1)=names; | |
66 names{1}=''; | |
67 end | |
68 | |
69 | |
70 |