loop of trapezoidal integration

I would like to integrate the single columns of a matrix and insert the obtained values in a row vector.
The procedure i have in mind is:
1 - select the first column of the matrix
2 -integrate following the trapezoidal rule
3 - insert the obtained value in a vector
4 - pass to the second column, and so on..

Read the matrix from file. The matrix is made of 11200 rows and 640 columns.
Here i take only the first 224 rows.

My code is:


double integrate(double w[], int n, double t);

int main()
{

// Open matrix
ifstream white("50frames.txt");
if (white.is_open()) {
for (int i = 0; i < 224; i++) {
for (int j = 0; j < 640; j++) {
white >> w[i][j];
}
}
}

// Select the first column

double col1[224];
double ans1 = 0;
for (int i = 0; i < 224; i++) {
col1[i] = w[i][0];
cout << col1[i]<<'\n';
}
cout << endl;


// Selection with for of every columns
double col2[224];
for (int i = 0; i < 224; i++) {
for (int j = 0; j << 640; j++) {
col2[i] = w[i][j];
}
}
cout << endl;


cout << integrate(col1, sizeof col1/sizeof col1[0], 1);
return 0;
}

// integration of the first column
double integrate(double col1[], int n, double t) {
double ans=0;
for (int i = 1; i < n; i++) {
ans += (((col1[i - 1] + col1[i])*t) / 2);
}

return ans;

system("pause");

}



Where i can place the routin for the integartion in order to integarte every single column and insert the value in a row vector?
Registered users can post here. Sign in or register to post.