In matlab we can use the matlab operator as follows:
M=[1 2 3 4, 5 6 7 8, 9 10 11 12]
M[:,1] = M[:,2] + M[:,3]
to apply the same operation to all the rows of a matrix
I’am wondering if we can apply a same operation to set values to a range of values in std::vector as it’s done with colon(:) matlab’s operator. Indeed, I’m using a vector to store the matrix values.
vector<int> M;
Thanks in advance.
There are C++ libraries that allow one to handle matrices pretty much as matlab does (allowing also for SIMD vectorization); you may want to consider eigen, for instance.
If you don’t want to rely on external library you may want to consider
std::valarraywhich has been explicitly thought for algebraic computations (withvalarrays you may usestd::slicesto extract submatrices as you need).