我有一個數組X有M * N個元素,我試圖用這個相同的數據創建一個大小爲M×N的矩陣A.我使用gsl作爲矩陣,X被聲明爲數組。我遇到了麻煩,我在矩陣中不斷重疊。將向量設置爲矩陣算法幫助在C++
這裏是什麼,我試圖做一個例子:
Vector X[4*2]
1,2,3,4,5,6,7,8
Matrix A 4X2
1, 2
3, 4
5, 6
7, 8
//heres one of my many fail attempts as an example
//creation of array X here
X[n*m] = someCbasedformulafromtheweb(n, m);
//gsl matrix allocation for matrix A N x M
gsl_matrix * A = gsl_matrix_alloc(n, m);
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
// setting the x[i*j] entry to gsl_matrix A at positions i , j
gsl_matrix_set (A,i,j, x[i*j]);
}
}
你能告訴我們嘗試了什麼,爲什麼它不起作用以便我們有一個起點? – Dan 2011-12-29 04:21:11
確定我現在編輯它 – pyCthon 2011-12-29 04:21:56