diff --git a/src/methods/nca/nca.cpp b/src/methods/nca/nca.cpp
index f6b0ba21e6a65dbba4ad9ea4f1029f5de4f0615b..5a25c6499402facd966280de2cfb2929f77d1fa1 100644
--- a/src/methods/nca/nca.cpp
+++ b/src/methods/nca/nca.cpp
@@ -37,7 +37,13 @@ void nca(	char const *optimizerType,
 {	
 	// convert the Prolog array to arma::mat
 	mat data = convertArrayToMat(dataMatArr, dataMatSize, dataMatRowNum);
-	
+	// check if labels fit the data
+    if (data.n_cols != rawLabelsArrSize)
+    {
+        raisePrologSystemExeption("The number of data points does not match the number of labels!");
+        return;
+    }
+
 	// convert the Prolog array to arma::rowvec
 	Row< size_t > rawLabels = convertArrayToVec(rawLabelsArr, rawLabelsArrSize);