首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >real_2d_array数据类型的ALGLIB库、for模型和错误语法

real_2d_array数据类型的ALGLIB库、for模型和错误语法
EN

Stack Overflow用户
提问于 2014-12-07 03:06:12
回答 1查看 495关注 0票数 0

我有3x大数值的矩阵,我想用多项式插值。从网络上看,我偶然发现了一个PSU ,它介绍了几种适合多变量数据的算法。我查找了第一个文件,现在我已经成功地在我的系统上安装了静态库ALGLIB。

问题:这里是使用我想要使用的算法的一个例子。这是简单而直接的。我遇到的问题与"real_2d_array xy“有关,在这个示例中,您将看到它被设置为一个字符串,如下所示

代码语言:javascript
复制
real_2d_array xy = "[[-1,0,2],[+1,0,3]]";

当我编译它和示例的其余部分时,它完成得很好,并且在给定期望的输出时运行时没有问题。但是,我的数据集很大,每个图上有30,000点,我创建了一个字符串来存储以上格式的所有这些点,如下所示;

代码语言:javascript
复制
    //definitions, functions and housekeeping

    xyz_data+="[";                   //First bracket.
    std::stringstream ss;            //Used to convert numbers to string

    // other code with loops and more house keeping

    //This part repeats for every point in my data set
    xyz_data+="[";
    ss<<lenght;
    xyz_data+=ss.str()+",";
    ss.str("");
    ss<<rval;
    xyz_data+=ss.str()+",";
    ss.str("");
    ss<<temp.size();
    xyz_data+=ss.str()+"],";

    //more unrelated stuff

    xyz_data.erase(xyz_data.size()-1);  //Delete the extra comma for the last data pointas a result of the loop above.

    xyz_data+="]";   //closing data to fit format in example from ALGLIB

    //Declaring data type for matrix, from the ALGLIB
    real_2d_array xyz;
    xyz=xyz_data;       //Because in the example the RHS is a string, I assumed this would work, but it does not. I get an error about data types.

    //Running interpolation
    double v;
    rbfmodel model;
    rbfcreate(2, 1, model);
    rbfsetpoints(model, xyz);
    rbfreport rep;
    rbfsetalgoqnn(model);
    rbfbuildmodel(model, rep);
    printf("%d\n", int(rep.terminationtype));
    v = rbfcalc2(model, 0.0, 0.0);
    printf("%.2f\n", double(v));

错误消息:operator=不匹配(操作数类型为'alglib::real_2d_array‘和'std::string {aka std::basic_string}'),

有人能解释一下如何使这件事成功吗?我遗漏了一些微妙的东西,或者说,它似乎是关于能够直接使用字符串,而不是变量。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-07 14:51:05

我知道发生了什么。事实证明,real_2d_array不会接受字符串,但它将接受字符,或者在我的例子中是一个字符数组。就这样。

我的实现是

代码语言:javascript
复制
    xyz_data.replace(xyz_data.size()-1,1,"]");       //Delete the extra comma as a result of the loop above.
    char *DATA=new char[xyz_data.size()];            //Declare pointer to my array and allocate memory.
    memcpy(DATA,xyz_data.c_str(),xyz_data.size()+1);   //Copy data from string to character.
    real_2d_array xyz(DATA);                           //Accepted like VISA. Works like a charm.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27339144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档