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 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启