C ++ version of linspace ()

I've been using this C ++ function emulating MATLAB & # 39; s linspace for quite some time:

cv :: Mat CR :: linspace (double p_start, double p_end, int p_interval) const {
double space = p_interval-1;
cv :: Mat mat (1, spacing + 1, CV_64F);
for (int i = 0; i <= mat.cols; i ++) {
mat.at(0, i) = p_start + i * (p_end - p_start) / spacing;
}
return mat
}

Now I am working with different data and I am faced with difficult to locate error messages, such as:

Program received signal SIGABRT, aborted.
0x00007fffed1c2e97 in raise () from /lib/x86_64-linux-gnu/libc.so.6

I'm not completely sure what causes this but I noticed that in the linspace function, should not the for loop be designed without a < instead of a <=? If this is true, could it be that, depending on the situation of the memory, this would sometimes throw an error and sometimes not?