Error using pdist2 Too many input arguments

来源:互联网 发布:表格软件扫描录入 编辑:程序博客网 时间:2024/06/05 03:13

PS:遇到的问题

Error using pdist2

Too many input arguments.

 

Error inExhaustiveSearcher/knnsearch (line 207)

       [dist,idx] = pdist2(obj.X,Y, distMetric,arg{:}, 'smallest',numNN);

 

Error in ClassificationKNN/score(line 322)

            [CIDX,dist] = knnsearch(this.NS,X,'k',this.ModelParams.NumNeighbors,...

 

Error inClassificationKNN/predict (line 587)

                 posteriors = score(this,X);

 

Error in KNN_hog_new(line 16)

characterClass=predict(mdl,testHistograms(1,20:30));

解决:

help pdist2

 Calculates the distance between sets of vectors.

 

  LetX be an m-by-p matrix representing m points in p-dimensional space

  andY be an n-by-p matrix representing another set of points in the same

  space. This function computes the m-by-ndistance matrix D where D(i,j)

  isthe distance between X(i,:) and Y(j,:). This function has been

 optimized where possible, with most of the distance computations

 requiring few or no loops.

 

  Themetric can be one of the following:

 

 'euclidean' / 'sqeuclidean':

   Euclidean / SQUARED Euclidean distance. Note that 'sqeuclidean'

   is significantly faster.

 

 'chisq'

   The chi-squared distance between two vectors is defined as:

    d(x,y) = sum( (xi-yi)^2 / (xi+yi) ) / 2;

   The chi-squared distance is useful when comparing histograms.

 

 'cosine'

   Distance is defined as the cosine of the angle between two vectors.

 

 'emd'

   Earth Mover's Distance (EMD) between positive vectors (histograms).

   Note for 1D, with all histograms having equal weight, there is a simple

   closed form for the calculation of the EMD.  The EMD between histograms

    xand y is given by the sum(abs(cdf(x)-cdf(y))), where cdf is the

   cumulative distribution function (computed simply by cumsum).

 

 'L1'

   The L1 distance between two vectors is defined as:  sum(abs(x-y));

 

 

 USAGE

   D= pdist2( X, Y, [metric] )

 

 INPUTS

  X        - [m x p] matrix of mp-dimensional vectors

  Y        - [n x p] matrix of np-dimensional vectors

  metric   - ['sqeuclidean'],'chisq', 'cosine', 'emd', 'euclidean', 'L1'

 

 OUTPUTS

  D        - [m x n] distance matrix

 

 EXAMPLE

   %simple example where points cluster well

  [X,IDX] = demoGenData(100,0,5,4,10,2,0);

   D= pdist2( X, X, 'sqeuclidean' );

  distMatrixShow( D, IDX );

   %comparison to pdist

  n=500; d=200; r=100; X=rand(n,d);

  tic, for i=1:r, D1 = pdist( X, 'euclidean' ); end, toc

  tic, for i=1:r, D2 = pdist2( X, X, 'euclidean' ); end, toc

  D1=squareform(D1); del=D1-D2; sum(abs(del(:)))

 

  Seealso pdist, distMatrixShow

 

  Piotr's Image&Video Toolbox      Version 2.52

  Copyright 2012 Piotr Dollar.  [pdollar-at-caltech.edu]

  Please email me if you find bugs, or havesuggestions or questions!

  Licensed under the Simplified BSD License[see external/bsd.txt]

因为安装了Piotr'sImage&Video Toolbox这一工具箱,其里面也有同名函数,导致调用的是工具箱的函数,而不是matlab里头的函数。把这个toolboox的路径从path中删除就可以了。

所以一般发生too many input argument大部分原因都是因为自定义函数和系统函数重名。想要知道是不是这一错误,只要help 一下相关的文件名就可以了。

之前用低于10个变量的参数可以计算以为是matlab内置pdist2的函数问题。

1 0