After more tries I have implemented the function by use of TypedIterators, which bypasses the issue of unable to access data using indexes like v[index].
Sadly the use of this mex function as a part of my MATLAB simulation slows the process down instead of accelerating it, compared to the MATLAB function. Maybe it is overheads?
double interpl_last_val(double xq, matlab::data::TypedArray<double> x, matlab::data::TypedArray<double> v)
{
matlab::data::TypedIterator<double> it = x.begin();
matlab::data::TypedIterator<double> iq = v.begin();
for (auto& elem : x){
if (elem > xq)
break;
++iq;
}
return *(--iq);
}
However, I am dont know how one will then access specific data from a multi-dimensional array or cell? Is the only way to manipulate iterators by adding/substracting assuming row/column major rules?