using matlab::engine::MATLABEngine from MexFunction::operator() to call the "path" matlab function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
From the Matlab Command Window, calling for path works normally.
From a C++-mexFunction I try to do the same.
Doing so, I have this error :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/365644/image.png)
void MexFunction::operator()(mm::ArgumentList outputs, mm::ArgumentList inputs)
{
auto matlabptr = getEngine();
matlab::data::ArrayFactory f;
auto emptyArray = f.createScalar("");
auto path = matlabptr->feval(matlab::engine::convertUTF8StringToUTF16String("path"),emptyArray);
if (path.getNumberOfElements() > 0) {
std::string myPath = matlab::data::TypedArray<matlab::data::MATLABString>(path)[0];
std::cout << myPath << std::endl;
}else{
std::cout << "Rate" <<std::endl;
}
}
Where do I goof ?
-----------------------
Edit and solve
path with one argument written this way in the `Command Window` will generate this error. I wanted to call it with no arguments, thus I had to do the following
void MexFunction::operator()(mm::ArgumentList outputs, mm::ArgumentList inputs)
{
md::TypedArray<md::MATLABString> values = inputs[0];
std::cout << "Going to run " << (std::string)values[0] <<std::endl;
auto matlabptr = getEngine();
matlab::data::ArrayFactory f;
auto emptyArray = f.createEmptyArray();
auto res = matlabptr->feval((std::string)values[0],1, {}); // <- this is the correct interface to call
auto tmp = md::CharArray(res[0]);
std::cout << tmp.toAscii() << std::endl;
}
0 commentaires
Réponses (1)
Voir également
Catégories
En savoir plus sur Start MATLAB and Call Functions from C++ Applications dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!