annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/sompak_sammon.m @ 0:cc4b1211e677 tip

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