IsInZone - Test when the animal is in a given zone. Test when the animal is in a given zone of the experimental setup (typically the firing field of a place cell). USAGE status = IsInZone(positions,zone) positions position <a href="matlab:help samples">samples</a> (normalized in [0,1]) zone test area, obtained using e.g. <a href="matlab:help FiringMap">FiringMap</a> or <a href="matlab:help DefineZone">DefineZone</a> OUTPUT status a logical vector indicating whether the animal was within (value 1) or outside (value 0) the zone at each timestamp NOTE In matrix 'zone', columns (resp. rows) correspond to x values (resp. y values) for position samples. SEE See also FiringMap, MapStats, DefineZone.
0001 function status = IsInZone(positions,zone) 0002 0003 %IsInZone - Test when the animal is in a given zone. 0004 % 0005 % Test when the animal is in a given zone of the experimental setup (typically the 0006 % firing field of a place cell). 0007 % 0008 % USAGE 0009 % 0010 % status = IsInZone(positions,zone) 0011 % 0012 % positions position <a href="matlab:help samples">samples</a> (normalized in [0,1]) 0013 % zone test area, obtained using e.g. <a href="matlab:help FiringMap">FiringMap</a> or <a href="matlab:help DefineZone">DefineZone</a> 0014 % 0015 % OUTPUT 0016 % 0017 % status a logical vector indicating whether the animal was within 0018 % (value 1) or outside (value 0) the zone at each timestamp 0019 % 0020 % NOTE 0021 % 0022 % In matrix 'zone', columns (resp. rows) correspond to x values (resp. y values) 0023 % for position samples. 0024 % 0025 % SEE 0026 % 0027 % See also FiringMap, MapStats, DefineZone. 0028 0029 0030 % Copyright (C) 2004-2011 by Michaƫl Zugaro 0031 % 0032 % This program is free software; you can redistribute it and/or modify 0033 % it under the terms of the GNU General Public License as published by 0034 % the Free Software Foundation; either version 3 of the License, or 0035 % (at your option) any later version. 0036 0037 % Check number of parameters 0038 if nargin < 2, 0039 error('Incorrect number of parameters (type ''help <a href="matlab:help IsInZone">IsInZone</a>'' for details).'); 0040 end 0041 0042 if isempty(positions), 0043 status = logical(zeros(size(positions,1),1)); 0044 return; 0045 end 0046 0047 % Check parameter sizes 0048 if ~islmatrix(zone) && ~islvector(zone), 0049 error('Parameter ''zone'' should be a logical vector or matrix (type ''help <a href="matlab:help IsInZone">IsInZone</a>'' for details).'); 0050 end 0051 if islvector(zone), 0052 zone = logical(zone(:))'; 0053 end 0054 if size(zone,1) > 2 && size(positions,2) < 3, 0055 error('Parameter ''positions'' should have at least 3 columns (type ''help <a href="matlab:help IsInZone">IsInZone</a>'' for details).'); 0056 end 0057 if islvector(zone) && size(positions,2) > 2, 0058 error('Parameter ''positions'' should have 2 columns (type ''help <a href="matlab:help IsInZone">IsInZone</a>'' for details).'); 0059 end 0060 0061 % Discretize abscissae 0062 x = positions(:,2); 0063 if max(x) > 1 || min(x) < 0, 0064 error('X coordinates should contain values in [0 1].'); 0065 end 0066 X = size(zone,2); 0067 x = Bin(x,[0 1],X); 0068 0069 % Discretize ordinates 0070 if ~islvector(zone), 0071 y = positions(:,3); 0072 if max(y) > 1 || min(y) < 0, 0073 error('Y coordinates should contain values in [0 1].'); 0074 end 0075 Y = size(zone,1); 0076 y = Bin(y,[0 1],Y); 0077 end 0078 0079 % Now (x,y) are matrix indices in 'zone'. Convert them to linear indices 0080 if ~islvector(zone), 0081 i = y+(x-1)*Y; 0082 else 0083 i = x; 0084 end 0085 % Return timestamps for those indices that fall in the zone 0086 status = zone(i);