GG西瓜 2022-09-01 15:15 采纳率: 76.9%
浏览 34
已结题

关于代码错误,如何解决?(语言-c语言)

要制作一个二维除噪的程序
遇到了下面的问题,希望得到解决
中间有省略

int main()
{
float dt, dx, h, c, x, t, win[N] = { 0.1,0.2,0.4,0.2,0.1 };
int nt, nx, nv, iv, it, ix, N2 = N / 2;
float **data = NULL;
float **denoised;
float *w;

w = read_1Dfloat("ricker.txt", &nv);
data = malloc_2D(nx, nt);
denoised = malloc_2D(nx, nt);
for (ix = 0; ix < nx; ix++)
{
    x = ix * dx;
    t = sqrt(x*x + 4 * h*h) / c;
    it = (int)(t / dt + 0.5);
    for (iv = 0; iv < nv; iv++)
        data[ix][it + iv] = w[iv];
}
for (ix = 0; ix < nx; ix++)
{
    float *noise;
    noise = randnoise(nt, 0.1);
    for (it = 0; it < nt; it++)
        data[ix][it] += noise[it];
    free(noise);
}
write_2Dfloatbin("prestack_noise.bin", data, nx, nt);
free(w);

for (ix = 0; ix < nx; ix++)
    for (it = 0; it < N2; it++)
        denoised[ix][it] = data[ix][it];
for (ix = 0; ix < nx; ix++)
    for (it = nt - N2; it < nt; it++)
        denoised[ix][it] = data[ix][it];

float *us = NULL;
us = (float *)malloc(sizeof(float) * nt);
for (it = 0; it < nt; it++)
    us[it] = 0.;
complex *tmp;
for (ix = 0; ix < nx; ix++)
{
    for (it = 0; it < nt; it++)
        us[it] = data[ix][it];
    tmp = conv(us, nt, win, N);                           该行有问题
    for (it = N2; it < nt - N2; it++)
    {
        denoised[ix][it] = tmp[it - N2 + N - 1];
    }
}

write_2Dfloatbin("prestack_denoised", denoised, nx, nt);

free(us);
free(data);
free(denoised);
return 0;

}

float *conv(float *x, int nx, float *h, int nh)
{
float *y = NULL;
int ny = nx + nh - 1, iy, ix;
y = (float *)malloc(sizeof(float)*ny);
for (iy = 0; iy < ny; iy++)
y[iy] = 0.;

for (iy = 0; iy < ny; iy++)
{
    for (ix = 0; ix < nx; ix++)
    {
        if (iy - ix >= 0 && iy - ix < nh)
            y[iy] += x[ix] * h[iy - ix];
    }
}
return y;

}

img


error C2440: '=' : cannot convert from 'float *' to 'struct comp *'
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct comp' (or there is no acceptable conversion)

  • 写回答

3条回答 默认 最新

  • 快乐鹦鹉 2022-09-01 15:24
    关注

    conv函数返回的是float *
    你调用的时候传递给了complex *

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月9日
  • 已采纳回答 9月1日
  • 创建了问题 9月1日

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示