pdist2 function

16 Ansichten (letzte 30 Tage)
A
A am 7 Feb. 2012
Kommentiert: Ana Gonçalves am 16 Feb. 2022
I'm trying to use the pdist2 function and keep getting this error: "??? Undefined function or method 'pdist2' for input arguments of type 'double'" The 'double' part changes depending on what data type I use, so that part can be ignored.
The statistics toolbox is in my path and I can do "help pdist2" and have the help file come up.
I have tried the examples within the help file and this still doesn't work.
The only thing I can think of is there is a function within pdist2 called partialSort, but no matter how much searching I do, I see no matlab function for this???
Anyone know why my pdist2 doesn't work?
  4 Kommentare
Sean de Wolski
Sean de Wolski am 8 Feb. 2012
I would guess it's not installed correctly. Is it on your path?
>>path
Ana Gonçalves
Ana Gonçalves am 16 Feb. 2022
As alternative, you can use this function I developed to replace pdist2.
You can thank me later ;)
function Distance = euclidean(x,y)
% This function replaces the function pdist2 available only at the Machine
% Learning toolbox. It computes the distances between rows of X.
% Autor: Ana C. Goncalves
% n = norm(v) returns the Euclidean norm of vector v. This norm is also
% called the 2-norm, vector magnitude, or Euclidean length.
for i = 1:length(x)
for j = 1:length(y)
if i ~= j
%Distance(i,j) = sqrt((x(i)-x(j))^2 + (y(i)-y(j))^2); % Don't literally work because calculates the distance btw thw columns.
Distance(i,j) = norm(x(i,:) - x(j,:));
end
end
end
end

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Benjamin Schwabe
Benjamin Schwabe am 7 Feb. 2012
Okay, my MATLAB does not know a pdist2 function, only pdist. (I am using MatLabd r2009b)
Could it be that simple?
Otherwise, in which folder is the pdist2.m file? Add this to the path or change working directory accordingly.
  1 Kommentar
A
A am 8 Feb. 2012
i'm using r2010b and pdist2 was added to this version

Melden Sie sich an, um zu kommentieren.


Chathurika
Chathurika am 20 Feb. 2013
if you don't have a working pdist2, use the following code..it could be little slower than pdist2..but works fine..
pairwise distance between rows of matrix A and B....A and B should have same no of columns....output D is a 2D matrix with ij entry giving distance between ith row of A and jth row of B....distance used is L1 norm..
tmpB(1,:,:)=B';
x=repmat(tmpB,[size(A,1),1,1]);
y=repmat(A,[1,1,size(x,3)]);
D(:,:)=sum(abs(x-y),2);

ROCKTIM JYOTI DAS
ROCKTIM JYOTI DAS am 28 Okt. 2019
how to compare two histogram of images
  1 Kommentar
Steven Lord
Steven Lord am 28 Okt. 2019
This isn't related to the original question. Please ask it as its own question. When you ask it as its own question, you should provide more details about how you want to compare the histograms (just answer "Are they the same?", answer "How many bins are different?", answer "How much does each bin differ between the two images?", etc.)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by