How can I convert a double
/float
-typed vector or matrix to an word
/uword
-typed vector or matrix?
I need to create an indexing array indices
.
vec t = linspace(0, 100);
double freq = 0.25;
indices = floor(t / freq);
I'm having trouble on the last line.
If you are just dealing with positive values, then the conv_to function of the armadillo package will do exactly the same as the method you are trying to use.
vec t = linspace(0, 100);
double freq = 0.25;
ivec indices = conv_to<ivec>::from(t / freq);
If you want the results to be the same as the use of the floor function for negative values of t, you could replace the last line with
ivec indices = conv_to<ivec>::from(floor(t / freq));
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