How can I call a matlab function that takes no arguments using matlab engine C++ API?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a matlab function (myFunc) that takes no arguments and returns a matlab string. I want to call this function using the matlab engine C++ API. In all examples I have found in documentation, the functions used receive at least one argument (like sqrt o gcd). I have tried declaring an empty variable and using it like this:
const matlab::data::Array arg;
auto res = matlabPtr->feval(u"myFunc", arg);
The code compiles OK, but when I run it I get the exception error "Default constructed arguments are not allowed"
Is there a way to call this kind of function?
Thank you for your help
3 Kommentare
dpb
am 15 Aug. 2024
I don't know anything about the toolbox and a quick look at the doc didn't answer the question, but the simple workaround would be to just pass an argument but ignore it inside the function.
If nobody who uses the toolbox that knows a real answer comes by shortly, I'd suggest submit an official support request; the Answers forum is not that...
Antworten (1)
Anshuman
am 20 Aug. 2024
When using the MATLAB Engine C++ API to call a MATLAB function that takes no arguments, you should not pass an empty Array as an argument. Instead, you should call the function with an empty argument list. Use the 'feval' method without passing any arguments, except for the function name and the number of output arguments you expect.
Here's how you can do it:
auto results = matlabPtr->feval(u"myFunc", 0, std::vector<matlab::data::Array>());
As per my understanding , by following this approach you should be able to call MATLAB functions with no input arguments using the MATLAB Engine C++ API.
Hope it helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Exchange and Mapping with C++ Applications finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!