Such a simple question but I haven't found an answer in the armadillo's documentation.
I'm looking for the Armadillo/C++ equivalent to Matlab's x = (1:n) where n is a number and x is thus a vector [1, 2, 3..., n-1, n].
Please, pay attention to this function.
vec v = linspace<vec>(1, N);
Generates a vector starting at 1 and ending at N. It does just what you need.
Assuming that c++11 is acceptable and you are using std::vector, you can use std::iota:
std::vector<int> x(n);
std::iota(x.begin(), x.end(), 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With