Daniel@0: function sMap=sompak_sammon(sMap,ft,cout,ct,rlen) Daniel@0: Daniel@0: %SOMPAK_SAMMON Call SOM_PAK Sammon's mapping program from Matlab. Daniel@0: % Daniel@0: % P = sompak_sammon(sMap,ft,cout,ct,rlen) Daniel@0: % Daniel@0: % ARGUMENTS ([]'s are optional and can be given as empty: [] or '') Daniel@0: % sMap (struct) map struct Daniel@0: % (string) filename Daniel@0: % [ft] (string) 'pak' or 'box'. Argument must be defined, if Daniel@0: % input file is used. Daniel@0: % [cout] (string) output file name. If argument is not defined Daniel@0: % (i.e argument is '[]') temporary file '__abcdef' is Daniel@0: % used in operations and *it_is_removed* after Daniel@0: % operations!!! Daniel@0: % [ct] (string) 'pak' or 'box'. Argument must be defined, if Daniel@0: % output file is used. Daniel@0: % rlen (scalar) running length Daniel@0: % Daniel@0: % RETURNS: Daniel@0: % P (matrix) the mapping coordinates Daniel@0: % Daniel@0: % Calls SOM_PAK Sammon's mapping program (sammon) from Matlab. Notice Daniel@0: % that to use this function, the SOM_PAK programs must be in your Daniel@0: % search path, or the variable 'SOM_PAKDIR' which is a string Daniel@0: % containing the program path, must be defined in the workspace. Daniel@0: % SOM_PAK programs can be found from: Daniel@0: % http://www.cis.hut.fi/research/som_lvq_pak.shtml Daniel@0: % Daniel@0: % See also SOMPAK_INIT, SOMPAK_SAMMON, SOMPAK_SAMMON_GUI, Daniel@0: % SOMPAK_GUI, SAMMON. Daniel@0: Daniel@0: % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas Daniel@0: % Copyright (c) by Juha Parhankangas Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Juha Parhankangas 050100 Daniel@0: Daniel@0: NO_FILE = 0; Daniel@0: Daniel@0: nargchk(5,5,nargin); Daniel@0: Daniel@0: if ~(isstruct(sMap) | isstr(sMap)) Daniel@0: error('Argument ''sMap'' must be a struct or filename.'); Daniel@0: end Daniel@0: Daniel@0: if isstr(sMap) Daniel@0: if isempty(ft) | ~isstr(ft) | ~(strcmp(ft,'pak') | strcmp(ft,'box')) Daniel@0: error('Argument ''ft'' must be string ''pak'' or ''box''.'); Daniel@0: end Daniel@0: if strcmp(ft,'pak') Daniel@0: sMap=som_read_cod(sMap); Daniel@0: else Daniel@0: new_var=diff_varname; Daniel@0: varnames=evalin('base','who'); Daniel@0: loadname=eval(cat(2,'who(''-file'',''',sMap,''')')); Daniel@0: if any(strcmp(loadname{1},evalin('base','who'))) Daniel@0: assignin('base',new_var,evalin('base',loadname{1})); Daniel@0: evalin('base',cat(2,'load(''',sMap,''');')); Daniel@0: new_var2=diff_varname; Daniel@0: Daniel@0: assignin('base',new_var2,evalin('base',loadname{1})); Daniel@0: assignin('base',loadname{1},evalin('base',new_var)); Daniel@0: evalin('base',cat(2,'clear ',new_var)); Daniel@0: sMap=evalin('base',new_var2); Daniel@0: evalin('base',cat(2,'clear ',new_var2)); Daniel@0: else Daniel@0: evalin('base',cat(2,'load(''',sMap,''');')); Daniel@0: sMap=evalin('base',loadname{1}); Daniel@0: evalin('base',cat(2,'clear ',loadname{1})); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: if ~isstr(cout) & isempty(cout) Daniel@0: NO_FILE = 1; Daniel@0: cout = '__abcdef'; Daniel@0: elseif ~isstr(cout) | isempty(cout) Daniel@0: error('Argument ''cout'' must be a string or ''[]''.'); Daniel@0: end Daniel@0: Daniel@0: if ~NO_FILE & (isempty(ct) | ~(strcmp(ct,'pak') | strcmp(ct,'box'))) Daniel@0: error('Argument ''ct'' must be string ''pak'' or ''box''.'); Daniel@0: end Daniel@0: Daniel@0: som_write_cod(sMap,cout); Daniel@0: Daniel@0: if ~is_positive_integer(rlen) Daniel@0: error('Argument ''rlen'' must be a positive integer.'); Daniel@0: end Daniel@0: Daniel@0: if any(strcmp('SOM_PAKDIR',evalin('base','who'))) Daniel@0: command=cat(2,evalin('base','SOM_PAKDIR'),'sammon '); Daniel@0: else Daniel@0: command='sammon '; Daniel@0: end Daniel@0: Daniel@0: str = sprintf('%s -cin %s -cout %s -rlen %d',command,cout,cout,rlen); Daniel@0: Daniel@0: if isunix Daniel@0: unix(str); Daniel@0: else Daniel@0: dos(str); Daniel@0: end Daniel@0: Daniel@0: sMap=som_read_cod(cout); Daniel@0: Daniel@0: if ~NO_FILE Daniel@0: if isunix Daniel@0: unix(cat(2,'/bin/rm ',cout)); Daniel@0: else Daniel@0: dos(cat(2,'del ',cout)); Daniel@0: end Daniel@0: if strcmp(ct,'box'); Daniel@0: sMap=sMap.codebook; Daniel@0: eval(cat(2,'save ',cout,' sMap')); Daniel@0: disp(cat(2,'Output is saved to the file ',sprintf('''%s.mat''.',cout))); Daniel@0: else Daniel@0: som_write_cod(sMap,cout); Daniel@0: sMap=sMap.codebook; Daniel@0: disp(cat(2,'Output is saved to the file ',cout,'.')); Daniel@0: end Daniel@0: else Daniel@0: if isunix Daniel@0: unix('/bin/rm __abcdef'); Daniel@0: else Daniel@0: dos('del __abcdef'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function bool = is_positive_integer(x) Daniel@0: Daniel@0: bool = ~isempty(x) & isreal(x) & all(size(x) == 1) & x > 0; Daniel@0: if ~isempty(bool) Daniel@0: if bool & x~=round(x) Daniel@0: bool = 0; Daniel@0: end Daniel@0: else Daniel@0: bool = 0; Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function str = diff_varname(); Daniel@0: Daniel@0: array=evalin('base','who'); Daniel@0: Daniel@0: if isempty(array) Daniel@0: str='a'; Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: for i=1:length(array) Daniel@0: lens(i)=length(array{i}); Daniel@0: end Daniel@0: Daniel@0: Daniel@0: ind=max(lens); Daniel@0: Daniel@0: str(1:ind+1)='a'; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: