Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何从C中的数组中选择特定范围的数据?_Arrays_C_Sorting_Date Range - Fatal编程技术网

Arrays 如何从C中的数组中选择特定范围的数据?

Arrays 如何从C中的数组中选择特定范围的数据?,arrays,c,sorting,date-range,Arrays,C,Sorting,Date Range,我使用的是带有数据流模式的双通道DAQ 输出数据将成为一个数组,然而,我只想从中获得一个特定的数据范围并进行计算和分析,否则太多的数据点将延迟系统并导致FIFO溢出 C代码是否具有类似于Matlabarray(6000:7000)的功能 这是我获取通道1和通道2数据的代码,我想从ch1Buffer[I]和ch2Buffer[I] uInt32 i, n; uInt8* pu8Buffer = NULL; int16* pi16Buffer = NULL; int64 i64Sum = 0; fl

我使用的是带有数据流模式的双通道DAQ

输出数据将成为一个数组,然而,我只想从中获得一个特定的数据范围并进行计算和分析,否则太多的数据点将延迟系统并导致FIFO溢出

C
代码是否具有类似于Matlab
array(6000:7000)
的功能

这是我获取通道1和通道2数据的代码,我想从
ch1Buffer[I]
ch2Buffer[I]

uInt32 i, n;
uInt8* pu8Buffer = NULL;
int16* pi16Buffer = NULL;
int64 i64Sum = 0;
float max1 = 0;
float max2 = 0;
double Corrected = 0;
double AUC = 0;
int16* ch1Buffer = NULL;
int16* ch2Buffer = NULL;
double SumBufferData( void* pBuffer, uInt32 u32Size, uInt32 u32SampleBits )
{
    // In this routine we sum up all the samples in the buffer. This function 
    // should be replaced with the user's analysys function
    if ( 8 == u32SampleBits )
    {
        pu8Buffer = (uInt8 *)pBuffer;
        for (i = 0; i < u32Size; i++)
        {
            i64Sum += pu8Buffer[i];
        }
    }
    else
    {
        pi16Buffer = (int16 *)pBuffer;
        fftw_complex(hilbertedch2[N]);

        ch1Buffer       = (int16*)calloc(u32Size/2, sizeof(int16));
        ch2Buffer       = (int16*)calloc(u32Size/2, sizeof(int16));

        // Divide ch1 and ch2 data from pi16Buffer
        for (i = 0; i < u32Size/2; i++)
        {
            ch1Buffer[i] += pi16Buffer[i*2];
            ch2Buffer[i] += pi16Buffer[i*2 + 1];
        }
        // Here hilbert on the whole ch2
        hilbert(ch2Buffer, hilbertedch2);

        //Find max value in each segs of ch1 and ch2
        for (i = 0; i < u32Size/2; i++)
        {
            if (ch1Buffer[i] > max1)
                max1 = ch1Buffer[i];

            if (abs(hilbertedch2[i][IMAG])> max2)
                max2 = abs(hilbertedch2[i][IMAG]);
        }
        Corrected = (max2 / max1); // Calculate the signal correction
    }
    free(ch1Buffer);
    free(ch2Buffer);
    return Corrected;
}
uInt32 i,n;
uInt8*pu8Buffer=NULL;
int16*pi16Buffer=NULL;
int64 i64Sum=0;
float max1=0;
float max2=0;
双重校正=0;
双AUC=0;
int16*ch1Buffer=NULL;
int16*ch2Buffer=NULL;
双SumBufferData(无效*pBuffer,uInt32 U32大小,uInt32 U32采样位)
{
//在这个例程中,我们汇总缓冲区中的所有样本
//应替换为用户的analysys功能
if(8==U32采样位)
{
pu8Buffer=(uInt8*)pBuffer;
对于(i=0;imax1)
max1=ch1Buffer[i];
if(abs(hilbertedch2[i][IMAG])>max2)
max2=abs(hilbertedch2[i][IMAG]);
}
校正=(max2/max1);//计算信号校正
}
免费(ch1Buffer);
免费(ch2Buffer);
回程修正;
}
C代码是否具有类似Matlab数组(6000:7000)的功能

是的,它叫
memcpy
。但作为C语言,它更难使用,而且它不知道数据的结构和大小

int source_array[500]; 
// assume array gets filled somehow

int dest_array[50];
// dest_array = source_array[100:150] (not C code)
memcpy(dest_array, &source_array[100], 50*sizeof(source_array[0]);

由于
memcpy
是高度优化的,每次都比for循环好。

您可以使用where,您可以将源地址作为起始地址,从您想要复制数据的位置,而不是范围,您可以提到需要从该起始地址复制的字节数,并且需要提供存储该数据的目标地址。并查看手册页以查看限制(源和目标不应重叠),谢谢,但它看起来像是针对Linux的。我用的是C,这合适吗?对于(I=6000;I<7000;I++){用数组[I]}做任何事情?它是a
C
function@Davide这看起来是最简单和直接的一个,我会试试看,谢谢!您好,如果我理解清楚,我将构建一个名为
ch2newBuffer
的新数组来获取我感兴趣的值,6000到7000范围从
ch2Buffer
memcpy
写入格式,它将变成
memcpy(ch2newBuffer,&ch2Buffer[6000],1000*sizeof(ch2Buffer[0])
我说得对吗?@kevin,是的。除非我完全误解了MatLab语法的作用。谢谢!顺便说一句,我打印答案时遇到了一个问题。我写了:
for(I=0;I<2;I++){printf(“a[%d]=%f\n”,I,*ch2newBuffer);ch2newBuffer++;
我只从
ch2Buffer
中选择了两个值,我想检查它们是否是我想要的。我如何修改这个打印输出函数?
在0x00007FFF4C2A1399(vcruntime140d.dll)抛出异常在Examplefordebug.exe:0xc000005:Access违例写入位置0x0000000000000000中。
问题已解决,但我仍会给您积分,谢谢!