function [lineara,linearb]=recindex(a,b) % [lineara,linearb]=RECINDEX(a,b) % % Returns the mapping of 'b' into the elements of 'a' % such that 'b(linearb) == a(lineara)' - % 'a' and 'b' may not both contain zeroes. % Usually, 'a' is the bigger set and 'b' is a possible subset, % 'a' may have some zeroes provided 'b' doesn't % Compare with the function 'ismember' and 'intersect' % 'a' must be a unique set % % Small matrices only! Needs max(length(a),length(b))^2 locations. % Round off floats 'cos they'll get squared and then rooted % % Last modified by fjsimons-at-alum.mit.edu, 06/18/2007 % 'a' and 'b' may not contain zeroes. % But if b does not contain any then it's ok if ~prod(a) & ~prod(b) error('Input matrices must not both contain zero elements') end % Map 'a' and 'b' into a row vector a=a(:)'; b=b(:)'; % Matrix 'a' must contain non-repeating elements if any(size(unique(a))~=size(a)) error('Matrix a must be a unique set') end % Make 'a' the greater set of the two if length(a)