PreviousIndexLast

[help-gsl] Re: how to covert from gsl_vector to double array for input to gsl_stats functions (2008-07-06)

From: Brian Gough <bjg@gnu.org>
Subject: Re: how to covert from gsl_vector to double array for input to gsl_stats functions
Date: Sun, 06 Jul 2008 21:36:54 +0100
To: "Michael Chen" <vancouver.michael@.........>
Cc: help-gsl@gnu.org

At Sat, 5 Jul 2008 11:07:42 -0500,
Michael Chen wrote:
> I would like to know how you deal with this situation. Please cc my
> email address as well, thanks!
>
> double data[m][n];
> FILE * in = fopen("kenneth48monthvalueweight.dat","r");
> gsl_matrix_fscanf(in,&vdata.matrix);
> gsl_matrix_view vdata = gsl_matrix_view_array (data[0],m,n);
> for (i=0;i<n;i++){
> gsl_vector_view column = gsl_matrix_column (&vdata.matrix, i);
> mean[i]=gsl_stats_mean(column.vector.data,1,m);

A column vector has a non-unit stride so the appropriate usage is
mean[i]=gsl_stats_mean(column.vector.data,column.vector.stride,m);

--
Brian Gough

GNU Scientific Library -
http://www.gnu.org/software/gsl/