comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/vis_planeGetArgs.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 [nargin_,varargout]=vis_planeGetArgs(varargin)
2
3 % VIS_PLANEGETARGS Subfunction for som_*plane: extracts topolopy
4 % information from the first arguments.
5 %
6 % [nargin,varargout]=vis_planeGetArgs(varargin)
7 %
8 % Input and output arguments:
9 % varargin (varies) arguments given to som_*plane function
10 % nargin_ (scalar) number of arguments that nargchk of som_*plane "should see"
11 % +number_of_varargins if varargin{1} is not map/topol struct
12 % +number_of_varargins+1 if varargin{2} is a map/topol struct
13 % varargout (varies) the arguments that som_*plane "should see"
14 %
15 % Basically, this function allows topology information to be given
16 % in various ways: either as a map/topology struct, or as a argument pair:
17 % lattice, msize. The topology is always converted into the (lattice, msize)
18 % argument pair.
19 % - if first input argument (varargin{1}) is a map or topol struct
20 % the function extracts lattice and msize fields to two first
21 % output variables after 'nargin_'.
22 % - otherwise it copies the input arguments to the output arguments
23 % after 'nargin_'.
24 % If there are too many inputs (as compared to number of outputs), the
25 % last ones are ignored. If too few, they are replaced by empty values
26 % in outputs.
27 %
28 % Example of usage:
29 % function definition: h = som_cplane(varargin)
30 % first code line: [nargin,lattice,msize,color,size,pos]=vis_planeGetArgs(varargin);
31 %
32 % See also SOM_CPLANE, SOM_BARPLANE, SOM_PLOTPLANE, SOM_PIEPLANE.
33
34 % Copyright (c) 2000 by the SOM toolbox programming team.
35 % http://www.cis.hut.fi/projects/somtoolbox/
36
37 % Version 2.0beta Johan 240300
38
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41 nout=nargout-1;
42
43 % Set first all varargins to contain empty (==default values in som_*plane)
44
45 for i=1:nout, varargout{i}=[]; end
46
47 nargin_ = nargin;
48 % Struct: might be map or topol
49
50 if isstruct(varargin{1}),
51
52 % Get topol from topol field
53 if isfield(varargin{1},'topol'), topol=varargin{1}.topol;
54 else topol=varargin{1}; % assume that this is topol struct
55 end
56
57 if ~isstruct(topol),
58 % topol not a struct !?
59 warning('Field ''topol'' is not a struct.');
60 varargout{1}=varargin{1};
61 varargoutC=2;
62 nargin_ = nargin;
63 elseif ~isfield(topol,'msize') | ~isfield(topol,'lattice'),
64 % Field missing?!
65 warning('Invalid topology struct.');
66 varargout{1}=topol;
67 varargoutC=2;
68 nargin_ = nargin;
69 else
70 varargout{1}=topol.lattice;
71 varargout{2}=topol.msize;
72 % increment input arg. counter
73 varargoutC=3;
74 nargin_ = nargin+1;
75 end
76
77 elseif iscell(varargin{1}),
78
79 c = varargin{1};
80 lattice = 'hexa'; shape = 'sheet'; msize = [1 1];
81 for i=1:length(c),
82 if ischar(c{i}),
83 switch c{i},
84 case {'hexa','hexaU','rect','rectU'}, lattice = c{i};
85 case {'sheet','cyl','toroid'}, shape = c{i};
86 end
87 else
88 msize = c{i};
89 end
90 end
91 varargout{1} = lattice;
92 varargout{2} = msize;
93 varargoutC=3;
94 nargin_ = nargin+1;
95
96 else
97
98 % should be a lattice (string)
99 varargout{1}=varargin{1};
100 varargoutC=2;
101 nargin_=nargin;
102
103 end
104
105 for i=2:nargin, varargout{varargoutC+i-2}=varargin{i}; end
106
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%