Arrays in higher dimensions

John Ketchum johnk@qualcomm.com
Tue Jul 16 06:25:00 GMT 2002


For 4-d array, with dimensions n1, n2, n3, and n4, something like the 
following:

gsl_matrix ***m4;
m4 = (gsl_matrix***)malloc(n4*sizeof(gsl_matrix**));
for (i=0; i<n4; i++) {
         m4[i] = (gsl_matrix**)malloc(n3*sizeof(gsl_matrix*));
         for (j=0; j<n3; j++) m4[i][j]=gsl_matrix_alloc(n1,n2);
}


This gives you a matrix of pointers to gsl matrices,  which is a 4-d construct.

Make sure you free all of the memory when you are done:

for (i=0; i<n4; i++) {
         for (j=0; j<n3; j++) gsl_matrix_free(m4[i][j]);
         free(m4[i]);
}
free(m4);



At 11:26 AM 7/16/2002 +0200, Przemyslaw Sliwa wrote:
>Hi,
>my problem is - is it possible to create an ayray of gsl_matrices and 
>gsl_vectors within the gsl library?
>I would like to create 3 and 4 dimansional arrays - that means I need one 
>and two dimensional array of
>gsl_matrices and gsl_vectors.
>
>If it is possible - how can I access the elements of such an array.
>Thanks to everyone.
>
>
>Przemyslaw Sliwa
>
>
>Witout stupid mementos.
>

John Ketchum
Qualcomm Inc.
9 Damonmill Square Suite 2A
Concord, MA 01742
Office: 60915
Direct: 781-276-0915
Fax: 781-276-0901
Mobile: 617-312-7023



More information about the Gsl-discuss mailing list