错误存储数据从std::Vector到Eigen::Vector。

huangapple go评论94阅读模式
英文:

Error storing data from std::Vector to Eigen::Vector

问题

以下是您提供的代码的翻译部分:

*error: no matching function for call to object of type 'Eigen::VectorXd' (aka 'Matrix<double, Dynamic, 1>')
DenseCoeffsBase.h:362:5: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:115:41: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:178:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided
DenseCoeffsBase.h:423:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided*

上述是当我尝试将数据从标准向量存储到Eigen向量时提供的错误消息。

这是我尝试的内容。我在其他文件中创建了标准向量,并通过这些命令返回它们,然后必须将它们转换为Eigen样式的向量以与其他代码集成。我尝试了查找将标准向量数据存储到Eigen的方法,我在另一个Stack Overflow帖子中找到了这种特定方法。我不明白这个错误消息是什么意思。有人能告诉我我做错了什么吗?

还有,在尝试打印数据时,我遇到了这个错误:"引用非静态成员函数必须调用它:你是不是打算不带参数调用它"。

我以为通过调整大小我使它成为了静态向量。

我会感激帮助,并会添加任何必要的信息。我对C++相对陌生,因此希望能够提供更简单的解释,因为我对所有基本原理都不是很熟悉。

simulator.h

Eigen::VectorXd currentStartMassVector_, currentEndMassVector_, specificImpulses_;
std::vector<double> StartMassVector_, endMassVector_, SpecificImpulseVector_;
simulator.cpp

currentStartMassVector_.resize(numberOfStages_);
currentEndMassVector_.resize(numberOfStages_);
specificImpulses_.resize(numberOfStages_);

StartMassVector_ = launchVehicle->getMassStartStages();
endMassVector_ = launchVehicle->getMassEndStages();
SpecificImpulseVector_ = launchVehicle->getCurrentSpecificImpulse();

currentStartMassVector_(StartMassVector_.data(), StartMassVector_.size());
currentEndMassVector_(endMassVector_.data(), endMassVector_.size());
specificImpulses_(SpecificImpulseVector_.data(), SpecificImpulseVector_.size());

std::cout << "start mass vector" << currentStartMassVector_.transpose << std::endl;
std::cout << "end mass vector" << currentEndMassVector_.transpose << std::endl;
std::cout << "Isp vector" << specificImpulses_.transpose << std::endl;

希望这些翻译对您有帮助。如果您有任何进一步的问题,请随时提出。

英文:
*error: no matching function for call to object of type &#39;Eigen::VectorXd&#39; (aka &#39;Matrix&lt;double, Dynamic, 1&gt;&#39;)
DenseCoeffsBase.h:362:5: note: candidate function not viable: no known conversion from &#39;double *&#39; to &#39;Eigen::Index&#39; (aka &#39;long long&#39;) for 1st argument; dereference the argument with *
DenseCoeffsBase.h:115:41: note: candidate function not viable: no known conversion from &#39;double *&#39; to &#39;Eigen::Index&#39; (aka &#39;long long&#39;) for 1st argument; dereference the argument with *
DenseCoeffsBase.h:178:5: note: candidate function not viable: requires single argument &#39;index&#39;, but 2 arguments were provided
DenseCoeffsBase.h:423:5: note: candidate function not viable: requires single argument &#39;index&#39;, but 2 arguments were provided*

The above was the error message provided when I try to store the data from a standard vector to a Eigen Vector

Here's what I'm trying to do. I've made std vectors in other files that I'm returning through those commands and then have to convert them to eigen style vectors to integrate with some other code.I have tried looking for ways to store std vector data into eigen and I found this particular way on another stack overflow post. I dont understand what the error messsage means. Can someone tell me what I'm doing wrong?

Also in an effort to print out the data, I get this error
"Reference to non static member function must be called:did you mean to call it with no arguments"

I thought I made it a static vector by resizing.

I'd appreciate help and will add any information necessary. I'm kind of new to C++, and would appreciate a bit simpler explanations as I'm not well versed with all the fundamentals.

    simulator.h
    
    Eigen::VectorXd currentStartMassVector_, currentEndMassVector_ ,specificImpulses_	;
    std::vector&lt;double&gt;       StartMassVector_, endMassVector_ , SpecificImpulseVector_  ;

    simulator.cpp
    
    currentStartMassVector_.resize(numberOfStages_);
    currentEndMassVector_.resize(numberOfStages_);
    specificImpulses_.resize(numberOfStages_);
    
    StartMassVector_ 			= launchVehicle-&gt;getMassStartStages();
    endMassVector_ 				= launchVehicle-&gt;getMassEndStages();
    SpecificImpulseVector_ 		= launchVehicle-&gt;getCurrentSpecificImpulse();
    
    currentStartMassVector_(StartMassVector_.data(),StartMassVector_.size())  ;
    currentEndMassVector_(endMassVector_.data(),endMassVector_.size()) ;
    specificImpulses_(SpecificImpulseVector_.data(),SpecificImpulseVector_.size());
    
    	std::cout &lt;&lt; &quot;start mass vector&quot; &lt;&lt;  currentStartMassVector_.transpose &lt;&lt; std::endl;
        std::cout &lt;&lt; &quot;end mass vector&quot;   &lt;&lt;  currentEndMassVector_.transpose &lt;&lt; std::endl;
    	std::cout &lt;&lt; &quot;Isp vector&quot; &lt;&lt;  specificImpulses_.transpose &lt;&lt; std::endl;

答案1

得分: 3

只能使用构造函数来初始化以前未声明的向量。
在这种情况下,Eigen向量已经在头文件中声明。

Eigen::Map() 可以用来将数据从 std::vector&lt;double&gt; 复制到 Eigen::VectorXd,就像这样:

currentStartMassVector_ = Eigen::Map<Eigen::VectorXd>(StartMassVector_.data(),StartMassVector_.size()) ;

英文:

You can only use the constructor to initialize a vector that was not previously declared.
In this case, the Eigen vectors are already declared in the header file.

Eigen::Map() can be used to copy the data from the std::vector&lt;double&gt; to the Eigen::VectorXd, like this:

currentStartMassVector_ = Eigen::Map&lt;Eigen::VectorXd&gt;(StartMassVector_.data(),StartMassVector_.size()) ;

huangapple
  • 本文由 发表于 2020年1月3日 16:46:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/59575488.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定