Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ armadillo cast/convert to integer type vector or matrix

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.

like image 690
Brian Avatar asked Dec 29 '14 19:12

Brian


1 Answers

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));
like image 99
Zak Kann Avatar answered Sep 19 '22 00:09

Zak Kann