Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: angular comparison?
Date: Fri, 4 Sep 2009 18:51:00 +0000 (UTC)
Organization: Mitre Corp
Lines: 26
Message-ID: <h7rnik$ceo$1@fred.mathworks.com>
References: <h7rmod$ii4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1252090260 12760 172.30.248.38 (4 Sep 2009 18:51:00 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Sep 2009 18:51:00 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2318
Xref: news.mathworks.com comp.soft-sys.matlab:568457


"Sven" <sven.holcombe@gmail.deleteme.com> wrote in message <h7rmod$ii4$1@fred.mathworks.com>...
> Hi there,
> I figured this would be a common problem, so there might be a simple trick already worked out.
> 
> How do I cluster variables that represent angles such that a value of 1 degree is deemed 'close' to 359 degrees?
> 
> Eg.
> 
> angles = rand(1,20)*360;
> 
> If I were working in a linear space a simple difference of two angles would give me their difference. But I think that my space is cyclic, so I'm not quite sure how to best have my space 'wrap around' from 360 back to 0, in preparation to do some clustering.
> 
> Thanks,
> Sven.

To name a few,

You could compare the sin (or cosine) of the angles:
doc sind
doc cosd

Or, you could use the modulus function on the angles directly
doc mod
doc rem

I'm sure there are many other ways alao.