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