using matlab::engine::MATLABEngine from MexFunction::operator() to call the "path" matlab function
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Vedere anche
Categorie
Scopri di più su Start MATLAB and Call Functions from C++ Applications in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!