column-sum

How to Sum Column of a Matrix and Store it in a Vector in C++

Is there a straight forward way to do it? I'm stuck here: #include <iostream> #include <vector> #include <cstdlib> using std::size_t; using std::vector; int main() { vector<vector<int> > Matrix; //Create the 2x2 matrix. size_t rows = 2; size_t cols = 2; // 1: set the number of rows. Matrix.resize(rows); for(size_t...

How do I divide matrix elements by column sums in MATLAB?

Is there an easy way to divide each matrix element by the column sum? For example: input: 1 4 4 10 output: 1/5 4/14 4/5 10/14 ...