在 C++ 中查找局部极值

Find local extrema in c++

本文关键字:查找局 C++      更新时间:2023-10-16

我试图在根直方图中找到局部极值。我的想法是将垃圾箱内容放在数组中并使用 pesistence1d 类。

第一步是创建一个简单的float数组并使用该类,使用以下简单代码

#include "persistence1d.hpp"
using namespace std;
using namespace p1d;
int main()
{
    float y[3] = {2,1,2}; 
    //cout << y[0] << y[1] << y[2] << endl; 
    //Run persistence on data - this is the main call.
    Persistence1D p;
    p.RunPersistence(y);
    return 0;
}

问题是当我使用 g++ extrema.cpp 编译此代码时,出现以下错误

extrema.cpp: In function ‘int main()’: 
extrema.cpp:20: error: no matching function for call to ‘p1d::Persistence1D::RunPersistence(float [3])’ 
persistence1d.hpp:128: note: candidates are: bool p1d::Persistence1D::RunPersistence(const std::vector<float, std::allocator<float> >&)

我不明白为什么会发生此错误!任何想法或建议将非常受欢迎!

尝试传递向量而不是数组:

std::vector<float> y;
y.push_back(2); y.push_back(1); y.push_back(2);
Persistence1D p;
p.RunPersistence(y);