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:
how could I deal with such error message

Subject: how could I deal with such error message

From: han

Date: 18 Jun, 2010 11:18:04

Message: 1 of 3

I am calculating the similarity in a big and very sparse matrix which dimensions are 940*1600,
I use the command of pdist(matrix,'cosine'), however, I got the following error message
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.

someone who can help me out of this trouble?
great thanks

Subject: how could I deal with such error message

From: Roger Stafford

Date: 18 Jun, 2010 12:01:07

Message: 2 of 3

"han " <samuel_han@hotmail.com> wrote in message <hvfklc$f8v$1@fred.mathworks.com>...
> I am calculating the similarity in a big and very sparse matrix which dimensions are 940*1600,
> I use the command of pdist(matrix,'cosine'), however, I got the following error message
> 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.
>
> someone who can help me out of this trouble?
> great thanks

  As the error message is telling you, some of your row vectors are so small in magnitude relative to others that the 'cosine' metric gives a meaningless result, so 'pdist' is complaining about this and refusing to cooperate.

  You say your matrix is sparse. Perhaps some of your row vectors are actually of zero magnitude. The 'cosine' metric requires that a division by the magnitude be performed, but in such vectors that would produce a NaN rather than a valid result.

Roger Stafford

Subject: how could I deal with such error message

From: Wayne King

Date: 18 Jun, 2010 12:09:05

Message: 3 of 3

"han " <samuel_han@hotmail.com> wrote in message <hvfklc$f8v$1@fred.mathworks.com>...
> I am calculating the similarity in a big and very sparse matrix which dimensions are 940*1600,
> I use the command of pdist(matrix,'cosine'), however, I got the following error message
> 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.
>
> someone who can help me out of this trouble?
> great thanks

Hi Han,

It's saying that you have rows in matrix with essentially zero norm. So, basically you have rows which are the zero vector. The cosine metric is

1- cos(theta)

where theta is the angle between the vectors represented by two rows. Think just in terms of vectors, what is the angle between any vector and the zero vector? That's why the warning is issued.

Wayne

Tags for 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