# KdTree Example

**URL:** <https://discourse.itk.org/t/kdtree-example/2567>\
**Category:** Algorithms\
**Created:** [December 23, 2019, 1:18pm UTC](https://discourse.itk.org/t/kdtree-example/2567 "2019-12-23T13:18:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fraca](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@fraca](https://discourse.itk.org/u/fraca)\
**Post date:** [December 23, 2019, 1:18pm UTC](https://discourse.itk.org/t/kdtree-example/2567/1 "2019-12-23T13:18:26Z")

</div>

I’m trying to run this [example](https://itk.org/Doxygen/html/Examples_2Statistics_2KdTreeBasedKMeansClustering_8cxx-example.html) but i have some issues with an error right here. Can you help me?

The error is related to the push\_back

> int index = 0;  
> for (unsigned int i = 0; i \< 2; i++)  
> {  
> MembershipFunctionType::Pointer membershipFunction = MembershipFunctionType::New();  
> MembershipFunctionType::CentroidType centroid(sample-\>GetMeasurementVectorSize());  
> for (unsigned int j = 0; j \< sample-\>GetMeasurementVectorSize(); j++)  
> {  
> centroid[j] = estimatedMeans[index++];  
> }  
> membershipFunction-\>SetCentroid(centroid);  
> membershipFunctionVector.push\_back(membershipFunction); //ERROR  
> }  
> classifier-\>SetMembershipFunctions(membershipFunctionVectorObject);

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [December 23, 2019, 2:46pm UTC](https://discourse.itk.org/t/kdtree-example/2567/2 "2019-12-23T14:46:10Z")

</div>

How is `membershipFunctionVector` defined? And what is the exact error message?

---

<div class="post-metadata">

**Author:** ![fraca](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@fraca](https://discourse.itk.org/u/fraca)\
**Post date:** [December 23, 2019, 4:10pm UTC](https://discourse.itk.org/t/kdtree-example/2567/3 "2019-12-23T16:10:16Z")

</div>

`membershipFunctionVector` is defined by:

> MembershipFunctionVectorType & membershipFunctionVector = membershipFunctionVectorObject-\>Get();

Error is about `allocation`, i will update you soon to give you more info about that
