Calling Matlab Function with Multiple Returns in C++ Semantic Error
Hello, I am running into a type error where I am not able to recieve multiple returns from a custom matlab function that gives multiple returns. Here is the C++ implementation, function and error message which is defined by the IDE as a semantic issue.
C++ CALL:
matlab::data::TypedArray<double> const errArray =
factory.createArray({1,10}, {-5.6355,-5.6188,-5.6022,-5.5856,-5.569,-5.5524,-5.5358,-5.5193,-5.5027,-5.4862});
std::vector<matlab::data::Array> args({errArray});
std::vector<matlab::data::Array> m_results = matlabPtr->feval(u"func",args);
MATLAB FUNCTION:
function [cnt,rng,mn,adq,des] = func(errArr)
matrix = rainflow(errArr);
cnt = matrix(:,1);
rng = matrix(:,2);
mn = matrix(:,3);
adq = 1;
des = 1;
end
ERROR MESSAGE (SEMANTIC ISSUE):
MatlabCall.cpp:80:38: No viable conversion from ‘matlab::data::Array’ to ‘std::vector<matlab::data::Array>’
stl_vector.h:553:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘const vector<Array> &’ for 1st argument
stl_vector.h:572:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘vector<Array> &&’ for 1st argument
stl_vector.h:625:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘initializer_list<value_type>’ (aka ‘initializer_list<matlab::data::Array>’) for 1st argument
stl_vector.h:497:7: explicit constructor is not a candidate
stl_vector.h:510:7: explicit constructor is not a candidate
I am wondering why the data type for m_results is matlab::data::array despite it being defined as a std::vector<matlab::data::Array>. The matlab engine is properly implemented and can run the multi-return example as provided here, https://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-c-1.html#mw_f777193c-c848-49fc-9591-bbb56a40a454, it just is seeming to have issue with my custom function.
I have tried the following:
give errArray as the feval argument (produces same error message)
define a size_t numReturned constant as shown in the documentation example (too many arguments error)
Thank you in advance.Hello, I am running into a type error where I am not able to recieve multiple returns from a custom matlab function that gives multiple returns. Here is the C++ implementation, function and error message which is defined by the IDE as a semantic issue.
C++ CALL:
matlab::data::TypedArray<double> const errArray =
factory.createArray({1,10}, {-5.6355,-5.6188,-5.6022,-5.5856,-5.569,-5.5524,-5.5358,-5.5193,-5.5027,-5.4862});
std::vector<matlab::data::Array> args({errArray});
std::vector<matlab::data::Array> m_results = matlabPtr->feval(u"func",args);
MATLAB FUNCTION:
function [cnt,rng,mn,adq,des] = func(errArr)
matrix = rainflow(errArr);
cnt = matrix(:,1);
rng = matrix(:,2);
mn = matrix(:,3);
adq = 1;
des = 1;
end
ERROR MESSAGE (SEMANTIC ISSUE):
MatlabCall.cpp:80:38: No viable conversion from ‘matlab::data::Array’ to ‘std::vector<matlab::data::Array>’
stl_vector.h:553:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘const vector<Array> &’ for 1st argument
stl_vector.h:572:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘vector<Array> &&’ for 1st argument
stl_vector.h:625:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘initializer_list<value_type>’ (aka ‘initializer_list<matlab::data::Array>’) for 1st argument
stl_vector.h:497:7: explicit constructor is not a candidate
stl_vector.h:510:7: explicit constructor is not a candidate
I am wondering why the data type for m_results is matlab::data::array despite it being defined as a std::vector<matlab::data::Array>. The matlab engine is properly implemented and can run the multi-return example as provided here, https://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-c-1.html#mw_f777193c-c848-49fc-9591-bbb56a40a454, it just is seeming to have issue with my custom function.
I have tried the following:
give errArray as the feval argument (produces same error message)
define a size_t numReturned constant as shown in the documentation example (too many arguments error)
Thank you in advance. Hello, I am running into a type error where I am not able to recieve multiple returns from a custom matlab function that gives multiple returns. Here is the C++ implementation, function and error message which is defined by the IDE as a semantic issue.
C++ CALL:
matlab::data::TypedArray<double> const errArray =
factory.createArray({1,10}, {-5.6355,-5.6188,-5.6022,-5.5856,-5.569,-5.5524,-5.5358,-5.5193,-5.5027,-5.4862});
std::vector<matlab::data::Array> args({errArray});
std::vector<matlab::data::Array> m_results = matlabPtr->feval(u"func",args);
MATLAB FUNCTION:
function [cnt,rng,mn,adq,des] = func(errArr)
matrix = rainflow(errArr);
cnt = matrix(:,1);
rng = matrix(:,2);
mn = matrix(:,3);
adq = 1;
des = 1;
end
ERROR MESSAGE (SEMANTIC ISSUE):
MatlabCall.cpp:80:38: No viable conversion from ‘matlab::data::Array’ to ‘std::vector<matlab::data::Array>’
stl_vector.h:553:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘const vector<Array> &’ for 1st argument
stl_vector.h:572:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘vector<Array> &&’ for 1st argument
stl_vector.h:625:7: candidate constructor not viable: no known conversion from ‘matlab::data::Array’ to ‘initializer_list<value_type>’ (aka ‘initializer_list<matlab::data::Array>’) for 1st argument
stl_vector.h:497:7: explicit constructor is not a candidate
stl_vector.h:510:7: explicit constructor is not a candidate
I am wondering why the data type for m_results is matlab::data::array despite it being defined as a std::vector<matlab::data::Array>. The matlab engine is properly implemented and can run the multi-return example as provided here, https://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-c-1.html#mw_f777193c-c848-49fc-9591-bbb56a40a454, it just is seeming to have issue with my custom function.
I have tried the following:
give errArray as the feval argument (produces same error message)
define a size_t numReturned constant as shown in the documentation example (too many arguments error)
Thank you in advance. c++, matlab engine, function, matlab engine api MATLAB Answers — New Questions