c++ - 我想从 C++ 代码将二维数组传递给八度函数“imregionalmax”
问题描述
我编写了一个 C++ 代码,我在其中读取一个 CSV 文件并将其存储到一个二维数组,然后将其传递给八度函数imregionalmax。但是代码给出了分段错误(核心转储)。请在这件事上帮助我。如果可能,请提供 C++ 代码。我在下面附上我的代码
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
#define ROW 100
#define COL 1000
int main (int argc, char **argv) {
std::ifstream f;
f.open ("Mat30.csv");
if (! f.is_open()) { /* validate file open for reading */
std::cerr << "error: file open failed '" << argv[1] << "'.\n";
return 1;
}
std::string line, val;
std::vector<std::vector<float>> array;
while (std::getline (f, line)) { /* read each line */
std::vector<float> v; /* row vector v */
std::stringstream s (line); /* stringstream line */
while (getline (s, val, ',')) /* get each value (',' delimited) */
v.push_back (std::stof (val)); /* add to row vector */
array.push_back (v); /* add row vector to array */
string_vector argv_octave (2);
argv_octave(0) = "embedded";
argv_octave(1) = "-q";
octave_main (1, argv_octave.c_str_vec (), 2);
octave_value_list in1 , in2;
for(octave_idx_type i = 0 ; i < ROW ; i++) {
for(octave_idx_type j = 0 ; j < COL ; j++)
in1(j) = octave_value(array[i][j]);
in2(i) = in1;
}
// segmentation fault (core dumped) occurs here. Execution is not going further
octave_value_list out = feval ("imregionalmax", in2, 1);
return 0;
}
我正在使用 ubuntu 18.04 并且 Octave 安装在我的机器中我正在通过编写终端“ mkoctfile --link-stand-alone file_name.cpp -o file_name && ./file_name ”来运行代码
解决方案
推荐阅读
- java - ThreadLocal set() 然后立即 get() 并不总是获取值
- single-sign-on - 无法使用 Visualize.js 使用 Keycloak SSO 令牌登录
- javascript - 禁用手动键盘输入 JavaScript/Oracle JET
- pug - 哈巴狗表单输入类型=文本属性“大小”不起作用?
- amazon-web-services - AWS Lambda 无服务器应用程序 - .Net Core 与 Asp.Net Core(多个与单个)
- python - 子类化 Flask 可插拔视图以实现可扩展功能的最佳方式
- swift - 如何在帮助类中使用 DataSnapshot 对象?
- amazon-web-services - 无论登录如何,是否都有适用于 AWS 的通用 Cognito Id?
- r - 如何使用 R 删除多个文件的部分文件名
- unity3d - 从Android上的文件夹中迭代和读取文本文件