在向量的排序向量中查找特定值的索引范围
Find index range of specific values in sorted vector of vectors
我有一个x、y、z值的排序std::vector<std::vector<double>>
,如下所示,
0.0, 0.0, 0.0
0.0, 0.0, 0.1
0.0, 0.0, 0.2
0.0, 0.1, 0.0
0.0, 0.2, 0.1
0.0, 0.2, 0.3
我想找到特定x和y值的所有z值,ex-z值0.0,0.0,应返回
0.0, 0.0, 0.0
0.0, 0.0, 0.1
0.0, 0.0, 0.2
我试过使用
struct MatchDouble
{
MatchDouble(double _x,double _y) : x(_x), y(_y) {}
bool operator()(std::vector<double> &n)
{
return fabs(x - n[0]) < FLT_EPSILON && fabs(y - n[1]) < FLT_EPSILON;
}
private:
double x, y ;
};
it = find_if(allpoints.begin(), allpoints.end(),MatchDouble(0.0,0.0));
但这只为我提供了一个向量值的迭代器。什么方法最适合实现这一点?
谢谢。
std::vector<std::vector<double>> ret;
std::copy_if(allpoints.begin(), allpoints.end(), std::back_inserter(ret), MatchDouble(0.0,0.0));
return ret;
这将创建一个与allpoints
类型相同的新vector
ret,并使用copy_if
仅复制兴趣点
相关文章:
- 在C++中调整向量中的索引
- 给定一个向量,如何找到该向量的所有子集和的原始索引
- 将转换字符键入 int 以用作向量C++的索引
- 在对向量中查找元素的索引
- 如何检查类实例向量的索引是否为空
- 如何根据排序索引的向量对 std::index 集进行排序?
- 向量索引变量声明(size_t 或 std::vector<DATATYPE>::size_type)
- 访问向量索引C++
- 包含全局最小值的向量索引
- C 向量由另一个向量索引
- 向量索引在C 中不会包裹吗?什么是解决方法
- 使用Armadillo库中的指数向量索引矩阵
- 将多个整数添加到一个向量索引? 'Cout'不起作用
- array:将一维数组的索引转换为多维数组的向量索引
- 将一维"flattened"索引转换为 N 维数组的 N 维向量索引
- 向量索引访问与迭代器访问的效率
- 特征矩阵支持由向量索引吗?
- 如何重写由向量索引指向的项?
- 在另一个向量中引用向量索引时出错:'std::out_of_range at memory location'
- c++帮助传递向量索引到函数