Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Cosine Similarity

Subject: Cosine Similarity

From: Rahul Singhal

Date: 7 May, 2010 08:54:05

Message: 1 of 2

I am trying to get the cosine similarity between rows in a matrix containing 1's and 0's. I am using the matlab function :

D = pdist(X,'cosine')

where X = matrix

But when i run the command, it gives the following error:

??? Error using ==> pdist at 174
Some points have small relative magnitudes, making them effectively zero.
Either remove those points, or choose a distance other than cosine.

So how can i overcome this error. can somebody help me plz..



Subject: Cosine Similarity

From: Mongkut Piantanakulchai

Date: 7 May, 2010 10:14:04

Message: 2 of 2

I guess the vectors that contain all zeros might cause the problem.
This is because the dot product should be divided by the product of matrix norm (magnitude) which will become zero). Division by zero might cause problem in that function.
Remove all vectors that contains all zeros may help.
If you still need those vectors that contains all zeros then you can choose other similarity measures.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us