Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/sompak_sammon.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 sMap=sompak_sammon(sMap,ft,cout,ct,rlen) | |
2 | |
3 %SOMPAK_SAMMON Call SOM_PAK Sammon's mapping program from Matlab. | |
4 % | |
5 % P = sompak_sammon(sMap,ft,cout,ct,rlen) | |
6 % | |
7 % ARGUMENTS ([]'s are optional and can be given as empty: [] or '') | |
8 % sMap (struct) map struct | |
9 % (string) filename | |
10 % [ft] (string) 'pak' or 'box'. Argument must be defined, if | |
11 % input file is used. | |
12 % [cout] (string) output file name. If argument is not defined | |
13 % (i.e argument is '[]') temporary file '__abcdef' is | |
14 % used in operations and *it_is_removed* after | |
15 % operations!!! | |
16 % [ct] (string) 'pak' or 'box'. Argument must be defined, if | |
17 % output file is used. | |
18 % rlen (scalar) running length | |
19 % | |
20 % RETURNS: | |
21 % P (matrix) the mapping coordinates | |
22 % | |
23 % Calls SOM_PAK Sammon's mapping program (sammon) from Matlab. Notice | |
24 % that to use this function, the SOM_PAK programs must be in your | |
25 % search path, or the variable 'SOM_PAKDIR' which is a string | |
26 % containing the program path, must be defined in the workspace. | |
27 % SOM_PAK programs can be found from: | |
28 % http://www.cis.hut.fi/research/som_lvq_pak.shtml | |
29 % | |
30 % See also SOMPAK_INIT, SOMPAK_SAMMON, SOMPAK_SAMMON_GUI, | |
31 % SOMPAK_GUI, SAMMON. | |
32 | |
33 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas | |
34 % Copyright (c) by Juha Parhankangas | |
35 % http://www.cis.hut.fi/projects/somtoolbox/ | |
36 | |
37 % Juha Parhankangas 050100 | |
38 | |
39 NO_FILE = 0; | |
40 | |
41 nargchk(5,5,nargin); | |
42 | |
43 if ~(isstruct(sMap) | isstr(sMap)) | |
44 error('Argument ''sMap'' must be a struct or filename.'); | |
45 end | |
46 | |
47 if isstr(sMap) | |
48 if isempty(ft) | ~isstr(ft) | ~(strcmp(ft,'pak') | strcmp(ft,'box')) | |
49 error('Argument ''ft'' must be string ''pak'' or ''box''.'); | |
50 end | |
51 if strcmp(ft,'pak') | |
52 sMap=som_read_cod(sMap); | |
53 else | |
54 new_var=diff_varname; | |
55 varnames=evalin('base','who'); | |
56 loadname=eval(cat(2,'who(''-file'',''',sMap,''')')); | |
57 if any(strcmp(loadname{1},evalin('base','who'))) | |
58 assignin('base',new_var,evalin('base',loadname{1})); | |
59 evalin('base',cat(2,'load(''',sMap,''');')); | |
60 new_var2=diff_varname; | |
61 | |
62 assignin('base',new_var2,evalin('base',loadname{1})); | |
63 assignin('base',loadname{1},evalin('base',new_var)); | |
64 evalin('base',cat(2,'clear ',new_var)); | |
65 sMap=evalin('base',new_var2); | |
66 evalin('base',cat(2,'clear ',new_var2)); | |
67 else | |
68 evalin('base',cat(2,'load(''',sMap,''');')); | |
69 sMap=evalin('base',loadname{1}); | |
70 evalin('base',cat(2,'clear ',loadname{1})); | |
71 end | |
72 end | |
73 end | |
74 | |
75 if ~isstr(cout) & isempty(cout) | |
76 NO_FILE = 1; | |
77 cout = '__abcdef'; | |
78 elseif ~isstr(cout) | isempty(cout) | |
79 error('Argument ''cout'' must be a string or ''[]''.'); | |
80 end | |
81 | |
82 if ~NO_FILE & (isempty(ct) | ~(strcmp(ct,'pak') | strcmp(ct,'box'))) | |
83 error('Argument ''ct'' must be string ''pak'' or ''box''.'); | |
84 end | |
85 | |
86 som_write_cod(sMap,cout); | |
87 | |
88 if ~is_positive_integer(rlen) | |
89 error('Argument ''rlen'' must be a positive integer.'); | |
90 end | |
91 | |
92 if any(strcmp('SOM_PAKDIR',evalin('base','who'))) | |
93 command=cat(2,evalin('base','SOM_PAKDIR'),'sammon '); | |
94 else | |
95 command='sammon '; | |
96 end | |
97 | |
98 str = sprintf('%s -cin %s -cout %s -rlen %d',command,cout,cout,rlen); | |
99 | |
100 if isunix | |
101 unix(str); | |
102 else | |
103 dos(str); | |
104 end | |
105 | |
106 sMap=som_read_cod(cout); | |
107 | |
108 if ~NO_FILE | |
109 if isunix | |
110 unix(cat(2,'/bin/rm ',cout)); | |
111 else | |
112 dos(cat(2,'del ',cout)); | |
113 end | |
114 if strcmp(ct,'box'); | |
115 sMap=sMap.codebook; | |
116 eval(cat(2,'save ',cout,' sMap')); | |
117 disp(cat(2,'Output is saved to the file ',sprintf('''%s.mat''.',cout))); | |
118 else | |
119 som_write_cod(sMap,cout); | |
120 sMap=sMap.codebook; | |
121 disp(cat(2,'Output is saved to the file ',cout,'.')); | |
122 end | |
123 else | |
124 if isunix | |
125 unix('/bin/rm __abcdef'); | |
126 else | |
127 dos('del __abcdef'); | |
128 end | |
129 end | |
130 | |
131 | |
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
133 | |
134 function bool = is_positive_integer(x) | |
135 | |
136 bool = ~isempty(x) & isreal(x) & all(size(x) == 1) & x > 0; | |
137 if ~isempty(bool) | |
138 if bool & x~=round(x) | |
139 bool = 0; | |
140 end | |
141 else | |
142 bool = 0; | |
143 end | |
144 | |
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
146 | |
147 function str = diff_varname(); | |
148 | |
149 array=evalin('base','who'); | |
150 | |
151 if isempty(array) | |
152 str='a'; | |
153 return; | |
154 end | |
155 | |
156 for i=1:length(array) | |
157 lens(i)=length(array{i}); | |
158 end | |
159 | |
160 | |
161 ind=max(lens); | |
162 | |
163 str(1:ind+1)='a'; | |
164 | |
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 |