c - How to use for loop to use a partion of a table? -




i have code , want partion table inp[2560] 4 parts , each part want calculate this:

mi = calcul__min(inp,640); ma = calcul__max(inp,640); moy = calcul__moy(inp,640); ectt = calcul__ect(inp,640); 

i don't know how use for-loop this.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h>  #define order 65  #define np 2560  float inp[2560]; float ed1, ed2, ed3, ed4, ap4; float d1, d2, d3, d4, a4, total; int i;  double calcul__max(float tab[], int n) {     double max;     int i;     (i = 0; < n; i++)     {         if(tab[i]>max)         max=tab[i];     }     return max; }  double calcul__min(float tab[], int n) {     double min;     int i;     (i = 0; < n; i++)     {         if(tab[i]<min)         min=tab[i];     }     return min; }  double calcul__moy(float tab[],int n) {     double  moyenne,somme;     int i;     (i = 0; < n; i++)     {         somme = somme + tab[i];         moyenne = somme /640;     }     return  moyenne; }  float calcul__ect(float tab[], int n) {     double moyenne, tm, som, ec, ect;     moyenne = calcul__moy(inp,640);     int i;      (i = 0; < n; i++)     {         tm = tab[i] - moyenne;         tm *= tm;         som += tm;     }     ec = som / 639;     ect = sqrt(ec);      return ect; }  struct calculstat {     float ea;     float amplitudemin;     float ecarttype;     float ed2;     float amplitudemax; };  filter(int ord, float *a, float *b, int np, float *x, float *y) {     int i, j;     y[0] = b[0] * x[0];     (i = 1; < ord + 1; i++) {         y[i] = 0.0;         (j = 0; j < + 1; j++)             y[i] = y[i] + b[j] * x[i-j];         (j = 0; j < i; j++)             y[i] = y[i] - a[j+1] * y[i-j-1];     }     (i = ord + 1; < np + 1; i++) {         y[i] = 0.0;         (j = 0; j < ord + 1; j++)             y[i] = y[i] + b[j] * x[i-j];         (j = 0; j < ord; j++)             y[i] = y[i] - a[j+1] * y[i-j-1];     } }  main() {     float x[np]= { -84.786,...};     float y[np], a[order+1], b[order+1];     int i, j;     b[0] = -0.005574892;     // [...]     b[65] = -0.005574892;      a[0] = 0;     // [...]     a[65] = 0;      filter(order, a, b, np, x, y);      (i = 0; < np; i++)     {         x[i]=y[np-i-1];     }     filter(order,a,b,np,x,y);     (i=0;i<np;i++)     {         x[i] = y[np-i-1];     }     (i = 0; < np; i++)     {         y[i] = x[i];     }     (i = 0; < np; i++)     {         //printf("%f\n",y[i]);         inp[i]=y[i];     }      double ma,mi,moy;     float ectt;      mi = calcul__min(inp,640);     ma = calcul__max(inp,640);     moy = calcul__moy(inp,640);     ectt = calcul__ect(inp,640);      printf("le min de tableau est ""%f\n",mi);     printf("le max de tableau est ""%f\n",ma);     printf ("la moyenne est de ""%g\n", moy);     printf ("ecart type est ""%g\n", ectt); } 

as know, arrays in c passed pointer first byte.

and know can apply pointer arithmetics on pointers in c (except void).

here example

#include <stdio.h>  void foo(float *f) {     // stuff }  int main() {     float inp[2560];     foo(inp);     foo(inp+(640));     foo(inp+(2*640));     foo(inp+(3*640)); } 

inp+x skips x floats in array. dont explicitly type x * sizeof(float); wrong.

i have code , want partion table inp[2560] 4 part , each part want calculate :

here inspiration:

int = 0; while (i < 4) {     whatever = calcul__min(inp+(i * 640),640); } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -