Daniel@0: function [S,m,l,t,s]=som_grid(varargin) Daniel@0: Daniel@0: %SOM_GRID Visualization of a SOM grid Daniel@0: % Daniel@0: % [sGrid,m,l,t,s]=som_grid(sGrid, ['argID', value, ...]) Daniel@0: % [sGrid,m,l,t,s]=som_grid(topol, ['argID', value, ...]) Daniel@0: % [sGrid,m,l,t,s]=som_grid(lattice, msize, ['argID', value, ...]) Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional) Daniel@0: % sGrid (struct) som_grid struct (see output arguments) Daniel@0: % topol (struct) map or topol struct for giving the topology Daniel@0: % (cell array) of form {'lattice', msize, ['shape']}. Daniel@0: % Default value for 'shape' is 'sheet'. Daniel@0: % lattice (string) 'hexa', 'rect' Daniel@0: % (matrix) size M x M, defines topological connections Daniel@0: % msize (vector) 1x2 vector defines the grid size, M=msize(1)*msize(2) Daniel@0: % ['argID',(string) Other arguments can be given as 'argID', value Daniel@0: % value] (varies) pairs. See list below for valid values. Daniel@0: % Daniel@0: % sGrid (struct) with fields S.msize, S.shape, S.lattice, S.coord, S.marker, Daniel@0: % S.markersize, S.markercolor, S.line, S.linewidth, S.linecolor, Daniel@0: % S.surf, S.label, S.labelsize, S.labelcolor Daniel@0: % m (matrix) handels to LINE objects (unit markers) Daniel@0: % l (matrix) handles to LINE objects (lines connecting the units) Daniel@0: % t (matrix) handles to TEXT objects (labels) Daniel@0: % s (scalar) handle to SURF object (surface between units) Daniel@0: % Daniel@0: % Here are the valid argument IDs (case insensitive) and Daniel@0: % associated values: Daniel@0: % 'Coord' Mx2 or Mx3 matrix of coordinates Daniel@0: % (default: according to lattice as in som_cplane) Daniel@0: % 'Marker' string 'o','+','x','*','v','^','<','>','h','s','d','p','.', Daniel@0: % 'none' or Mx1 cell or char array of these strings Daniel@0: % Default: 'o'. Daniel@0: % 'MarkerSize' scalar or Mx1 matrix of double. Default: 6. Daniel@0: % 'MarkerColor' ColorSpec or Mx3 matrix of RGB triples. Default: 'k'. Daniel@0: % 'Line' string '-',':','--' or '-.' or 'none'. Default: '-'. Daniel@0: % 'Surf' [], Mx1 or Mx3 matrix of RGB triples Daniel@0: % to define surface values. Default: [] = no surf. Daniel@0: % Note: shading is turned to 'interp'. Daniel@0: % 'LineWidth' scalar or MxM matrix, default: 0.5 Daniel@0: % 'LineColor' ColorSepc, MxMx3 matrix of RGB triples or a cell array Daniel@0: % of form {r g b} where r,g, and b are MxM Daniel@0: % (sparse) matrices of R,G, and B values Daniel@0: % 'Label' Mx1 char array, cell array of strings size MxL Daniel@0: % or [] to indicate no labels, default: [] = no labels. Daniel@0: % 'LabelSize' scalar Daniel@0: % 'LabelColor' ColorSpec or string 'none', default: 'g'. Daniel@0: % Daniel@0: % For more help, try 'type som_grid' or check out online documentation. Daniel@0: % See also SOM_CONNECTION, SOM_SHOW, SOM_CPLANE, SOM_SET, SCATTER, SCATTER3. Daniel@0: Daniel@0: %%%%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Daniel@0: % som_grid Daniel@0: % Daniel@0: % PURPOSE Daniel@0: % Daniel@0: % To visualize the SOM grid in various ways Daniel@0: % Daniel@0: % SYNTAX Daniel@0: % Daniel@0: % [sGrid,m,l,t,s]=som_grid(sGrid) Daniel@0: % [sGrid,m,l,t,s]=som_grid(sTopol) Daniel@0: % [sGrid,m,l,t,s]=som_grid(sMap) Daniel@0: % [sGrid,m,l,t,s]=som_grid({lattice, msize, [shape]}) Daniel@0: % [sGrid,m,l,t,s]=som_grid(lattice, msize) Daniel@0: % [sGrid,m,l,t,s]=som_grid(..., ['argID', value, ...]) Daniel@0: % Daniel@0: % DESCRIPTION Daniel@0: % Daniel@0: % The SOM can be defined as a set of units (neurons) and their Daniel@0: % topological relations. This function is used to visualize these in Daniel@0: % various ways. The units may be drawn using different markers and Daniel@0: % colors, in different sizes and in different locations in 2D or Daniel@0: % 3D. However the topological neighborhood is limited to be Daniel@0: % 2-dimensional. The connections between these units may be drawn using Daniel@0: % lines having different thicknesses and colors. Labeling text may be Daniel@0: % plotted on the units. It is possible also to draw a surface between Daniel@0: % the units. The surface coloring is either indexed (one value per Daniel@0: % unit) or fixed RGB (a 1x3 RGB triple per unit). Daniel@0: % Daniel@0: % REQUIRED INPUT ARGUMENTS Daniel@0: % Daniel@0: % Note: M is the number of map units. Daniel@0: % Daniel@0: % The first (or first two) argument may have various different types of values Daniel@0: % Daniel@0: % 1. sGrid (struct) som_grid struct (the output of this function) Daniel@0: % Daniel@0: % The struct initiates the visualization. The argID-value -pairs Daniel@0: % are used to alter the initiation. Daniel@0: % Daniel@0: % Following argument types may be used to give the topology for the grid Daniel@0: % Daniel@0: % 2. sTopol (struct) som_topol struct Daniel@0: % 3. sMap (struct) som_map struct (only topology matters) Daniel@0: % 4. {lattice, msize} or {lattice, msize, sheet} (cell array) Daniel@0: % - lattice must be 'hexa' or 'rect' Daniel@0: % - msize must be a 1x2 vector Daniel@0: % - shape (if specified) must be string 'sheet', 'cyl' or 'toroid' Daniel@0: % If shape is not given it is 'sheet' by default. Daniel@0: % 5. lattice (string or matrix) AND msize (1x2 vector) as two separate arguments Daniel@0: % - lattice may be string 'rect' or 'hexa' or a connection matrix Daniel@0: % (see SOM_CONNECTION) to define a free topology. This connection Daniel@0: % matrix is of size MxM and its element i,j (i','h','s','d', 'p','.', or 'none' Daniel@0: % give the same marker for each unit. Daniel@0: % (cell array) of size Mx1 of previous strings gives individual Daniel@0: % markers for each unit. Daniel@0: % Daniel@0: % 'MarkerSize' Size (pt) of unit markers, default is 6 (pt). Daniel@0: % (scalar) gives the same size for every unit. Daniel@0: % (matrix) Mx1 gives an individual size for each unit marker. Daniel@0: % Daniel@0: % 'MarkerColor' Unit marker colors, default is 'k' Daniel@0: % (ColorSpec) gives the same color each unit. Daniel@0: % (matrix) Mx3 of RGB triples gives individual color for each unit Daniel@0: % Note that indexed coloring - like in SOM_CPLANE - is Daniel@0: % not possible. If indexed coloring is needed, you can Daniel@0: % use SOM_NORMCOLOR to calculate RGB colors that Daniel@0: % emulate indexed coloring. However, the colors for the Daniel@0: % units are fixed, so changing colormap will not Daniel@0: % change the colors. Daniel@0: % Daniel@0: % 'Line' Line type, default is '-'. Daniel@0: % (string) '-',':','--' or '-.' or 'none'. Only one linetype in Daniel@0: % grid is allowed. Daniel@0: % Daniel@0: % 'LineWidth' Width of the topological connection lines (edges) Daniel@0: % (scalar) gives the same width for each line. Default is 0.5. Daniel@0: % (matrix) MxM sparse (or full) matrix gives individual width for Daniel@0: % each connection. The element (i,j), i= i are ignored in Daniel@0: % order to avoid ambiguous situations if the matrix would be Daniel@0: % non-symmetric. The "connections to oneself" is not drawn. Daniel@0: % Daniel@0: % Line width zero is valid and causes the line to disappear. Daniel@0: % Daniel@0: % 'LineColor' Color of connection lines, default is [0.9 0.9 0.9]. Daniel@0: % (ColorSpec) gives the same color for each line Daniel@0: % (matrix) MxMx3 matrix of RGB triples gives individual width for Daniel@0: % each connection. The element (i,j,:), i= i are ignored in order to avoid ambiguous situations Daniel@0: % if the matrix was non-symmetric. The "connections to oneself" Daniel@0: % is not drawn. Daniel@0: % Daniel@0: % Daniel@0: % 'Label' Labels for units, default is []. Daniel@0: % (empty) [] means no labels. Daniel@0: % (char array) of size Mx1. Element (i,:) has the label for unit i. Daniel@0: % (cell array) of size MxL consisting of sets of labels. Element {i,:} Daniel@0: % contains the labeling for unit i. Daniel@0: % In case of multiple labels, the labels for one unit are shown Daniel@0: % in one column centered at that unit. Daniel@0: % Daniel@0: % 'LabelSize' Text size of labels (points), default is 10. Daniel@0: % (scalar) Default is 10. Daniel@0: % Daniel@0: % 'LabelColor' Color of labels, default is 'c' (cyan). Daniel@0: % (ColorSpec) gives the same color for each label string 'xor' Daniel@0: % sets the colors automatically so that they differ Daniel@0: % from the background (using Matlab's built-in xor-color feature.) Daniel@0: % Daniel@0: % 'Surf' Surface between nodes, default is []. Daniel@0: % (empty) [] gives no surface Daniel@0: % (vector) Mx1 gives an indexed interpolated color surface between Daniel@0: % units using the actual colormap. Daniel@0: % (matrix) Mx3 matrix of RGB triples gives a interpolated color surface Daniel@0: % between units using fixed RGB colors. Daniel@0: % Daniel@0: % Note that the interpolation is done using Matlab's built-in Daniel@0: % color interpolation for SURF objects. Daniel@0: % Daniel@0: % OUTPUT ARGUMENTS Daniel@0: % Daniel@0: % sGrid (struct) with fields S.msize, S.shape, S.lattice, S.coord, S.marker, Daniel@0: % S.markersize, S.markercolor, S.line, S.linewidth, S.linecolor, Daniel@0: % S.surf, S.label, S.labelsize, S.labelcolor Daniel@0: % Daniel@0: % m (matrix) handels to LINE objects (unit markers) Daniel@0: % Daniel@0: % l (matrix) handles to LINE objects (lines connecting the units) Daniel@0: % Daniel@0: % t (matrix) handles to TEXT objects (labels) Daniel@0: % Daniel@0: % s (scalar) handle to SURF object (surface between units) Daniel@0: % Daniel@0: % EXAMPLES Daniel@0: % Daniel@0: % % Make map of size 15x10 on random data: Daniel@0: % Daniel@0: % map=som_make(rand(1000,4),'msize',[15 10], 'lattice', 'hexa'); Daniel@0: % Daniel@0: % % Draw the grid using two frist varable values as coordinates Daniel@0: % % and store the sGrid struct in varable S: Daniel@0: % Daniel@0: % S=som_grid(map, 'coord', map.codebook(:,[1 2])) Daniel@0: % Daniel@0: % %Define some things: Daniel@0: % % Daniel@0: % % Create a cell array of size 150x1 that divides map in to two label classes Daniel@0: % % 'circles' and 'squares' Daniel@0: % Daniel@0: % L(1:75,1)='o'; L(76:150,1)='s'; L = cellstr(L); Daniel@0: % Daniel@0: % % Create a coloring according to the 3rd variable according to current Daniel@0: % % colormap: Daniel@0: % Daniel@0: % C = som_normcolor(map.codebook(:,3)); Daniel@0: % Daniel@0: % % Change the visualization: use black lines, unit markers in M and unit Daniel@0: % % color in C, and set unit size to 10: Daniel@0: % Daniel@0: % S=som_grid(S, 'linecolor', 'k', 'marker', L, 'MarkerColor',C, ... Daniel@0: % 'MarkerSize', 10); Daniel@0: % Daniel@0: % % Do a new visualization, use indexed color surface calcualted from the Daniel@0: % % first variable, coordinates according to the lattice (default) but Daniel@0: % % no markers nor lines: Daniel@0: % Daniel@0: % S=som_grid(map,'line','none','marker','none','surf',map.codebook(:,1)); Daniel@0: % Daniel@0: % % Set coordinates according to three last varables Daniel@0: % Daniel@0: % som_grid(S,'coord',map.codebook(:,2:4)); Daniel@0: % Daniel@0: % % Create a random connection matrix R1 and the usual hexagonal Daniel@0: % % neighborhood connection matrix R2: Daniel@0: % Daniel@0: % R1=sparse(rand(150,150)>0.9); Daniel@0: % R2=som_connection(map); Daniel@0: % Daniel@0: % % Show these connections. Note that coordinates _must_ now be given Daniel@0: % % explicitly: we form default topological coordinates using Daniel@0: % % som_unit_coords. Daniel@0: % Daniel@0: % som_grid(R1,map.topol.msize,'coord',som_unit_coords(map)); Daniel@0: % som_grid(R2,map.topol.msize,'coord',som_unit_coords(map)); Daniel@0: % Daniel@0: % % Show connections (R1 AND R2) Daniel@0: % som_grid(R2.*R2,map.topol.msize,'coord',som_unit_coords(map)); Daniel@0: % Daniel@0: % OBJECT TAGS Daniel@0: % Daniel@0: % No tags are set. Daniel@0: % Daniel@0: % SEE ALSO Daniel@0: % Daniel@0: % som_show The basic map visualization routine Daniel@0: % som_cplane The basic component plane visualization Daniel@0: % som_connection The basic topological connections Daniel@0: % scatter Scatter plots Daniel@0: % scatter3 3-dimensional scatter plots Daniel@0: Daniel@0: % Copyright (c) 1999-2000 by the SOM toolbox programming team. Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta Johan 061099 juuso 151199 310300 Daniel@0: Daniel@0: %% Init %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: True=1; False=0; % const. Daniel@0: m=[]; l=[]; t=[]; s=[]; % default values for outputs Daniel@0: Ref=som_set('som_grid'); % reference struct Daniel@0: Daniel@0: num_of_args=length(varargin); % numb. of varargins Daniel@0: Daniel@0: if num_of_args==0, Daniel@0: S=som_set('som_grid'); Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: switch class(varargin{1}) Daniel@0: case 'struct' Daniel@0: S=varargin{1}; Daniel@0: first_identifier=2; Daniel@0: if ~isfield(S,'type'), Daniel@0: error('Input struct is invalid: field ''type'' is missing.'); Daniel@0: end Daniel@0: switch S.type Daniel@0: case 'som_grid' Daniel@0: S=varargin{1}; Daniel@0: first_identifier=2; Daniel@0: case 'som_map' Daniel@0: Ref.lattice=S.topol.lattice; Daniel@0: Ref.msize=S.topol.msize; Daniel@0: Ref.shape=S.topol.shape; Daniel@0: S=Ref; Daniel@0: first_identifier=2; Daniel@0: case 'som_topol' Daniel@0: Ref.lattice=S.lattice; Daniel@0: Ref.msize=S.msize; Daniel@0: Ref.shape=S.shape; Daniel@0: S=Ref; Daniel@0: first_identifier=2; Daniel@0: otherwise Daniel@0: error('Input struct has to be of type som_grid, som_map or som_topol.'); Daniel@0: end Daniel@0: case 'cell' Daniel@0: S=varargin{1}; Daniel@0: first_identifier=2; Daniel@0: if vis_valuetype(S,{'topol_cell_no_shape'}), Daniel@0: Ref.lattice=S{1}; Daniel@0: Ref.msize=S{2}; Daniel@0: elseif vis_valuetype(S,{'topol_cell'}), Daniel@0: Ref.lattice=S{1}; Daniel@0: Ref.msize=S{2}; Daniel@0: Ref.shape=S{3}; Daniel@0: else Daniel@0: error(['The cell value for 1st argument has to be {lattice, msize}' ... Daniel@0: 'or {lattice, msize, shape}.']); Daniel@0: end Daniel@0: S=Ref; Daniel@0: case{'double','sparse','char'} Daniel@0: % Set defaults Daniel@0: S=Ref; Daniel@0: first_identifier=3; Daniel@0: if num_of_args<2, Daniel@0: error('Not enough input arguments.'); Daniel@0: end Daniel@0: S.lattice=varargin{1}; Daniel@0: S.msize=varargin{2}; Daniel@0: otherwise Daniel@0: error('Invalid input arguments!'); Daniel@0: end Daniel@0: Daniel@0: %% Check input args %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: for i=first_identifier:2:num_of_args, Daniel@0: if ischar(varargin{i}) & isfield(Ref,lower(varargin{i})), Daniel@0: if i+1>num_of_args, Daniel@0: error('Invalid identifier-value pairs or wrong argument order.'); Daniel@0: else Daniel@0: S=setfield(S,lower(varargin{i}),varargin{i+1}); Daniel@0: end Daniel@0: elseif ischar(varargin{i}), Daniel@0: error(['Identifier ''' varargin{i} ''' is unknown.']); Daniel@0: else Daniel@0: error('Invalid identifier-value pairs or wrong argument order.'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % msize Daniel@0: Daniel@0: if ~vis_valuetype(S.msize,{'1x2'}), Daniel@0: error('msize has to be a 1x2 vector.'); Daniel@0: end Daniel@0: munits=prod(S.msize); Daniel@0: Daniel@0: % Default coordinates according to negihborhood Daniel@0: Daniel@0: if isempty(S.coord), Daniel@0: if ischar(S.lattice), Daniel@0: switch S.lattice, Daniel@0: case{'hexa','rect'} Daniel@0: S.coord=som_vis_coords(S.lattice,S.msize); Daniel@0: otherwise Daniel@0: error('String value for lattice must be ''hexa'' or ''rect''.'); Daniel@0: end Daniel@0: else Daniel@0: error('Lattice is not ''hexa'' or ''rect'': coordinates must be given.'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % connections Daniel@0: Daniel@0: type=class(S.lattice); Daniel@0: switch type Daniel@0: case {'sparse','double'} % free topology Daniel@0: fixedline=False; Daniel@0: case 'char' % default topologies (hexa,char) Daniel@0: switch S.lattice Daniel@0: case 'hexa' Daniel@0: hexa=True; Daniel@0: case 'rect' Daniel@0: hexa=False; Daniel@0: otherwise Daniel@0: error('Unknown lattice or neighborhood.'); Daniel@0: end Daniel@0: Daniel@0: % If topology is hexa/rect but linetype, color etc. is Daniel@0: % not constant, the topology is set to free Daniel@0: Daniel@0: if size(S.linewidth,1)>1 | size(S.linecolor,1)>1 | ... Daniel@0: iscell(S.linecolor) % matrix or cell = not constant Daniel@0: fixedline=False; Daniel@0: S.lattice=som_connection({S.lattice,S.msize,S.shape}); Daniel@0: else Daniel@0: fixedline=True; Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Check coordinate matrix size and set dummy zeros to z-axis Daniel@0: % if 2D coordinates (always 3D plots!) Daniel@0: Daniel@0: if ~vis_valuetype(S.coord,{[munits 2],[munits 3]}), Daniel@0: error('Coordinate matrix has wrong size.'); Daniel@0: elseif size(S.coord,2)==2, Daniel@0: S.coord(:,3)=0; Daniel@0: end Daniel@0: Daniel@0: % Fixed marker size, color, type? Daniel@0: Daniel@0: if size(S.markersize,1)>1 | size(S.markercolor,1)>1 | size(S.marker,1)>1 Daniel@0: fixedmarker=False; Daniel@0: else Daniel@0: fixedmarker=True; Daniel@0: end Daniel@0: Daniel@0: % Check labels Daniel@0: Daniel@0: if ~vis_valuetype(S.label,{'chararray','2Dcellarray_of_char'}) ... Daniel@0: & ~isempty(S.label), Daniel@0: error('Labels should be in a char array or cell array of strings.'); Daniel@0: elseif ischar(S.label) Daniel@0: S.label=cellstr(S.label); Daniel@0: end Daniel@0: Daniel@0: if size(S.label,1) ~= munits & ~isempty(S.label), Daniel@0: error('Number of labels and map size do not match.'); Daniel@0: end Daniel@0: Daniel@0: % Check line width, marker size, marker color, Daniel@0: % label size label color and surf sizes&types: Daniel@0: Daniel@0: if ~vis_valuetype(S.linewidth,{[munits munits] [1 1]}), Daniel@0: error('LineWidth matrix value has wrong size or dimension.'); Daniel@0: elseif any(S.linewidth(:)<0), Daniel@0: error('All elements of LineWidth must be non-negative.'); Daniel@0: elseif ~vis_valuetype(S.markersize,{[munits 1] [1 1]}), Daniel@0: error('MarkerSize matrix value has wrong size or dimension.'); Daniel@0: elseif any(S.markersize(:)<0), Daniel@0: error('All elements of MarkerSize must be non-negative.'); Daniel@0: elseif ~vis_valuetype(S.markercolor,{'1x3rgb','colorstyle'}) & ... Daniel@0: ~vis_valuetype(S.markercolor,{[munits 3],'nx3rgb'},'all'), Daniel@0: error('MarkerColor should be a ColorSpec or Mx3 matrix of RGB triples.'); Daniel@0: elseif ~vis_valuetype(S.labelcolor,{'1x3rgb','colorstyle','xor'}), Daniel@0: error('LabelColor shoud be a ColorSpec or ''xor'' or ''none''.') Daniel@0: elseif ~vis_valuetype(S.labelsize,{'1x1'}) Daniel@0: error('LabelSize should be a scalar.'); Daniel@0: elseif ~isempty(S.surf) & ~vis_valuetype(S.surf,{[munits 1] [munits 3]}); Daniel@0: error('Surf matrix value has wrong size or dimension.'); Daniel@0: end Daniel@0: Daniel@0: % Check marker type & size Daniel@0: Daniel@0: if vis_valuetype(S.marker,{'cellcolumn_of_char'}) Daniel@0: % Don't bother to check the mareker strings in this case Daniel@0: % let the plot3 handle them; it returns quite understandable Daniel@0: % error messages, anyway Daniel@0: Daniel@0: if ~size(S.marker) == [munits 1], Daniel@0: error(['Marker should be one of Matlab''s valid marker type,' ... Daniel@0: ' string ''none'' or a Mx1 cell array of these.']); Daniel@0: end Daniel@0: elseif ~vis_valuetype(S.marker,{'markerstyle','none'}), Daniel@0: error(['Marker should be one of Matlab''s valid marker type,' ... Daniel@0: ' string ''none'' or a Mx1 cell array of these.']); Daniel@0: end Daniel@0: Daniel@0: % Check line type & size: only one line style allowed Daniel@0: Daniel@0: if ~vis_valuetype(S.line,{'linestyle','none'}) Daniel@0: error(['Line should be a valid Matlab''s line style string or' ... Daniel@0: ' string ''none''.']); Daniel@0: end Daniel@0: Daniel@0: % Check line color Daniel@0: Daniel@0: if iscell(S.linecolor), Daniel@0: if ndims(S.linecolor) ~= 2 | any(size(S.linecolor) ~= [1 3]), Daniel@0: error('Cell input for LineColor should be of form {r,g,b}.') Daniel@0: elseif ~vis_valuetype(S.linecolor{1},{[munits munits],'nxn[0,1]'},'all')| ... Daniel@0: ~vis_valuetype(S.linecolor{2},{[munits munits],'nxn[0,1]'},'all')| ... Daniel@0: ~vis_valuetype(S.linecolor{3},{[munits munits],'nxn[0,1]'},'all'), Daniel@0: error(['In cell input {r,g,b} some matrix r,g or b is invalid: ' ... Daniel@0: 'Size must be MxM and values in interval [0,1].']); Daniel@0: end Daniel@0: elseif ~vis_valuetype(S.linecolor,{'colorstyle','1x3rgb'}) & ... Daniel@0: ~vis_valuetype(S.linecolor,{'nxnx3rgb', [munits munits 3]},'all'), Daniel@0: error('Invalid LineColor: see help text for valid values.'), Daniel@0: elseif vis_valuetype(S.linecolor, {'none'}), Daniel@0: error('LineColor ''none'' not allowed: set Line to ''none'' instead.'); Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% Action Daniel@0: Daniel@0: memhold=ishold; % take hold state Daniel@0: if ~memhold Daniel@0: cla; Daniel@0: end Daniel@0: hold on; Daniel@0: Daniel@0: % Set surf if it exist Daniel@0: Daniel@0: if ~isempty(S.surf), Daniel@0: for i=1:3, Daniel@0: s(:,:,i)=reshape(S.coord(:,i),S.msize); Daniel@0: end Daniel@0: s(:,:,4:3+size(S.surf,2))=reshape(S.surf,[S.msize size(S.surf,2)]); Daniel@0: s=surf(s(:,:,1),s(:,:,2),s(:,:,3),s(:,:,4:end)); Daniel@0: set(s,'EdgeColor','none','Marker','none','FaceColor','interp'); Daniel@0: end Daniel@0: Daniel@0: Daniel@0: if fixedline, Daniel@0: % Line properties are fixed: draw fast, but Daniel@0: % if line is set to 'none' set empty handle ans skip Daniel@0: if strcmp(S.line,'none') Daniel@0: l={}; Daniel@0: else Daniel@0: p1=reshape(S.coord, [S.msize 3]); Daniel@0: p2=zeros(size(p1)-[0 1 0]); Daniel@0: p2(1:2:end,:,:)=p1(1:2:end,2:end,:); Daniel@0: p2(2:2:end,:,:)=p1(2:2:end,1:end-1,:); Daniel@0: Daniel@0: l{1}=plot3(p1(:,:,1), p1(:,:,2), p1(:,:,3), ... Daniel@0: 'Color', S.linecolor(1,:), ... Daniel@0: 'LineWidth', S.linewidth(1), ... Daniel@0: 'LineStyle', S.line); Daniel@0: l{2}=plot3(p1(:,:,1)', p1(:,:,2)', p1(:,:,3)', ... Daniel@0: 'Color', S.linecolor(1,:), ... Daniel@0: 'LineWidth', S.linewidth(1), ... Daniel@0: 'LineStyle', S.line); Daniel@0: if hexa, Daniel@0: l{3}=plot3(p2(:,:,1), p2(:,:,2), p2(:,:,3), ... Daniel@0: 'Color', S.linecolor(1,:), ... Daniel@0: 'LineWidth', S.linewidth(1), ... Daniel@0: 'LineStyle', S.line); Daniel@0: end Daniel@0: end Daniel@0: l=cat(1,l{:}); Daniel@0: else Daniel@0: % Variable properties: draw connection by connection Daniel@0: Daniel@0: [I,J,lw]=find(S.lattice); Daniel@0: x=[S.coord(I,1)'; S.coord(J,1)']; Daniel@0: y=[S.coord(I,2)'; S.coord(J,2)']; Daniel@0: z=[S.coord(I,3)'; S.coord(J,3)']; Daniel@0: if S.linewidth(1)==0, Daniel@0: linewidth=0.5; Daniel@0: else Daniel@0: linewidth=S.linewidth(1); Daniel@0: end Daniel@0: if ndims(S.linecolor) ~= 3 Daniel@0: if isstr(S.linecolor) Daniel@0: l=plot3(x, y, z, ... Daniel@0: 'Color', S.linecolor, ... Daniel@0: 'LineWidth', linewidth, ... Daniel@0: 'LineStyle',S.line); Daniel@0: else Daniel@0: if iscell(S.linecolor) Daniel@0: lcolor=[S.linecolor{1}(1,1) S.linecolor{2}(1,1) S.linecolor{3}(1,1)]; Daniel@0: l=plot3(x, y, z, ... Daniel@0: 'Color', lcolor, ... Daniel@0: 'LineWidth', linewidth, ... Daniel@0: 'LineStyle',S.line); Daniel@0: else Daniel@0: l=plot3(x, y, z, ... Daniel@0: 'Color', S.linecolor(1,:), ... Daniel@0: 'LineWidth', linewidth, ... Daniel@0: 'LineStyle',S.line); Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: l=plot3(x, y, z, ... Daniel@0: 'Color', S.linecolor(1,1,:), ... Daniel@0: 'LineWidth', linewidth, ... Daniel@0: 'LineStyle',S.line); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: if fixedmarker, Daniel@0: Daniel@0: % If marker is set to 'none' skip and set empty handle Daniel@0: if strcmp(S.marker,'none') Daniel@0: m=[]; Daniel@0: else Daniel@0: % Fixed markers: draw all in one command Daniel@0: Daniel@0: m=plot3(S.coord(:,1), S.coord(:,2), S.coord(:,3), ... Daniel@0: 'LineStyle', 'none', ... Daniel@0: 'Marker', S.marker, ... Daniel@0: 'MarkerSize', S.markersize(1), ... Daniel@0: 'MarkerFaceColor', S.markercolor(1,:), ... Daniel@0: 'MarkerEdgeColor', S.markercolor(1,:)); Daniel@0: end Daniel@0: else Daniel@0: % Variable marker properties: draw marker by marker Daniel@0: Daniel@0: x=[S.coord(:,1)'; S.coord(:,1)']; Daniel@0: y=[S.coord(:,2)'; S.coord(:,2)']; Daniel@0: z=[S.coord(:,3)'; S.coord(:,3)']; Daniel@0: if iscell(S.marker) Daniel@0: marker=S.marker{1}; Daniel@0: else Daniel@0: marker=S.marker(1); Daniel@0: end Daniel@0: sz=max(S.markersize(1),0.1); Daniel@0: m=plot3(x, y, z, ... Daniel@0: 'LineStyle', 'none', ... Daniel@0: 'Marker', marker, ... Daniel@0: 'MarkerSize', sz, ... Daniel@0: 'MarkerFaceColor', S.markercolor(1,:), ... Daniel@0: 'MarkerEdgeColor', S.markercolor(1,:)); Daniel@0: end Daniel@0: Daniel@0: L=length(l); Daniel@0: n=munits; Daniel@0: Daniel@0: %%% Set variable properties %%% Daniel@0: Daniel@0: % Line width Daniel@0: Daniel@0: if length(S.linewidth)>1 Daniel@0: lwidth=diag(S.linewidth(I,J)); Daniel@0: Daniel@0: % Handle zero width Daniel@0: iszero=(lwidth == 0);lwidth(iszero)=0.5; Daniel@0: for i=1:length(l), Daniel@0: set(l(i),'LineWidth', lwidth(i)); Daniel@0: end Daniel@0: if ~isempty(iszero), % zero width Daniel@0: set(l(iszero),'Visible','off'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Line color Daniel@0: Daniel@0: if size(S.linecolor,1)>1 | iscell(S.linecolor) Daniel@0: if length(size(S.linecolor)) == 3 | iscell(S.linecolor) Daniel@0: if ~iscell(S.linecolor) Daniel@0: for i=1:L Daniel@0: set(l(i),'Color',S.linecolor(I(i),J(i),:)); Daniel@0: end Daniel@0: else Daniel@0: for i=1:L Daniel@0: lcolor=[S.linecolor{1}(I(i),J(i)),... Daniel@0: S.linecolor{2}(I(i),J(i)),... Daniel@0: S.linecolor{3}(I(i),J(i))]; Daniel@0: set(l(i),'Color',lcolor); Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: for i=1:L, Daniel@0: set(l(i),'Color', S.linecolor(I(i),:)); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Marker size Daniel@0: Daniel@0: if length(S.markersize)>1 Daniel@0: % handle zero size Daniel@0: iszero=find(~S.markersize); Daniel@0: S.markersize(iszero)=1; Daniel@0: for i=1:n, Daniel@0: set(m(i),'MarkerSize', S.markersize(i)); Daniel@0: end Daniel@0: if ~isempty(iszero), % zero size Daniel@0: set(m(iszero),'Visible','off'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Marker type Daniel@0: Daniel@0: if size(S.marker,1)>1 Daniel@0: S.marker=char(S.marker); Daniel@0: for i=1:n, Daniel@0: set(m(i),'Marker', S.marker(i)); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Marker color Daniel@0: Daniel@0: if size(S.markercolor,1)>1 Daniel@0: for i=1:n, Daniel@0: set(m(i),'MarkerFaceColor', S.markercolor(i,:), ... Daniel@0: 'MarkerEdgeColor', S.markercolor(i,:)); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Set labels if they exist Daniel@0: Daniel@0: if ~isempty(S.label) Daniel@0: if vis_valuetype(S.labelcolor,{'xor'}), Daniel@0: S.labelcolor='g'; Daniel@0: XOR=1; Daniel@0: else Daniel@0: XOR=0; Daniel@0: end Daniel@0: if vis_valuetype(S.labelcolor,{'none'}), Daniel@0: S.labelcolor='g'; Daniel@0: VIS = 1; Daniel@0: else Daniel@0: VIS = 0; Daniel@0: end Daniel@0: for i=1:size(S.label,1), Daniel@0: L=cat(1,S.label(i,:)); Daniel@0: for j=length(L):-1:1, Daniel@0: if isempty(L{j}), Daniel@0: L=L(1:end-1); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: if isempty(L), Daniel@0: L=''; Daniel@0: end Daniel@0: t(i)=text(S.coord(i,1), S.coord(i,2), S.coord(i,3), L,... Daniel@0: 'FontSize', S.labelsize, 'Color',S.labelcolor, ... Daniel@0: 'HorizontalAlignment', 'center'); Daniel@0: end Daniel@0: if XOR Daniel@0: set(t,'EraseMode','xor'); Daniel@0: end Daniel@0: if VIS Daniel@0: set(t,'Visible','off'); Daniel@0: end Daniel@0: else Daniel@0: t=[]; Daniel@0: end Daniel@0: Daniel@0: %% Set hold state Daniel@0: Daniel@0: if ~memhold, Daniel@0: hold off; Daniel@0: end Daniel@0: Daniel@0: if nargout==0, Daniel@0: clear S m l t s; Daniel@0: end