www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SpecifyTheMahalanobisDistanceForNearestNeighborSearchExample.m
%% Specify the Mahalanobis Distance for Nearest Neighbor Search %% % Load Fisher's iris data. Focus on the petal dimensions. % Copyright 2015 The MathWorks, Inc. load fisheriris X = meas(:,[3 4]); % Predictors %% % Prepare an exhaustive, nearest neighbors searcher. Specify to use the % Mahalanobis distance metric. Mdl = createns(X,'NSMethod','exhaustive','Distance','mahalanobis') %% % |Mdl| is an |ExhaustiveSearcher| model object. Access properties of % |Mdl| using dot notation. For example, use |Mdl.DistParameter| to % access the Mahalanobis covariance parameter. Mdl.DistParameter %% % You can pass query data and |Mdl| to: % % * <docid:stats_ug.buiwsyv knnsearch> to find indices and distances of nearest neighbors. % * <docid:stats_ug.buiyhlh rangesearch> to find indices of all nearest neighbors % within a distance that you specify.