# cluster

(method of orientation)

sort orientations into clusters

## Syntax

```[c,center] = cluster(ori,'numCluster',n)
[c,center] = cluster(ori,'maxAngle',omega)```

## Input

 ori orientation n number of clusters omega maximum angle

## Output

 c list of clusters center center of the clusters

## Example

```% generate orientation clustered around 5 centers
cs = crystalSymmetry('m-3m');
center = orientation.rand(5,cs);
odf = unimodalODF(center,'halfwidth',5*degree)
ori = odf.calcOrientations(3000);```
```
odf = ODF
crystal symmetry : m-3m
specimen symmetry: 1

kernel: de la Vallee Poussin, halfwidth 5°
center: Rotations: 5x1
weight: 1

```
```% find the clusters and its centers
tic; [c,centerRec] = cluster(ori,'numCluster',5); toc```
```Elapsed time is 9.426234 seconds.
```
```% visualize result
oR = fundamentalRegion(cs)
plot(oR)```
```
oR = orientationRegion
crystal symmetry:  432
face normales: 1 x 14
vertices: 1 x 24
```
```hold on
plot(ori.project2FundamentalRegion,c)
caxis([1,5])
plot(center.project2FundamentalRegion,'MarkerSize',10,'MarkerFaceColor','k','MarkerEdgeColor','k')
plot(centerRec.project2FundamentalRegion,'MarkerSize',10,'MarkerFaceColor','r','MarkerEdgeColor','k')
hold off```
```plot 2000 random orientations out of 3000 given orientations
```
```%check the accuracy of the recomputed centers
min(angle_outer(center,centerRec)./degree)```
```ans =
0.1965    0.3738    0.3482    0.2802    0.4471
```
```odfRec = calcODF(ori)
[~,centerRec2] = max(odfRec,5)
min(angle_outer(center,centerRec2)./degree)```
```
odfRec = ODF
crystal symmetry : m-3m
specimen symmetry: 1

Harmonic portion:
degree: 28
weight: 1

centerRec2 = orientation
size: 1 x 5
crystal symmetry : m-3m
specimen symmetry: 1

Bunge Euler angles in degree
phi1     Phi    phi2    Inv.
324.016 42.7375 13.4389       0
338.615  29.449 7.63752       0
345.647 41.3725 39.6826       0
56.3429 38.5128 291.192       0
59.8209 28.7906 317.858       0

ans =
2.5682    2.4932    0.3502    0.1637    0.3851
```