How do I retrieve a struct or cell array, or char vector, from an feval call to a Compiler SDK C++ MATLAB Data API Shared Library?

3 次查看(过去 30 天)
The MATLAB documentation page Writing C++ Driver Code Using the C++ MATLAB Data Array API explains how to write driver code that retrieves a numeric array from the result of an feval call to a MATLAB function. It would be useful to see how to retrieve a struct or cell array, or a char vector.

采纳的回答

Alan Frankel
Alan Frankel 2020-6-16
Follow the instructions under Generate a C++ MATLAB Data API Shared Library and Build a C++ Application, with these changes:
(1) In place of the file addmatrix.m in matlabroot\extern\examples\compilersdk\c_cpp\matrix, use the attached file subtractmatrix.m.
(2) If you want to test the function at the MATLAB Command Prompt, use this call:
[a, b, c] = subtractmatrix([19, 28, 37], [9, 8, 7])
rather than:
addmatrix([1 4 7; 2 5 8; 3 6 9], [1 4 7; 2 5 8; 3 6 9])
(3) Skip the step relating to creating a sample.
(4) Rather than copying and pasting the C++ driver code file generated in the samples folder, download the attached file subtractmatrix_mda.cpp.txt and change its name to subtractmatrix_mda.cpp.
(5) Use the call mbuild subtractmatrix_mda.cpp to compile and link the application.
When you run the application, you will see the same output generated at the MATLAB prompt by the MATLAB function subtractmatrix.m, followed by this output:
----------------------------------------------
Results retrieved via the MATLAB Data API:
Elements of mdaFinal:
10 20 30
Elements of mdaStruct[0]["elem1"]:
19 28 37
First element of mdaCellArray:
'Elements in astruct.elem1'
Second element of mdaCellArray:
3

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deploy to C++ Applications Using MATLAB Data API (C++11) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by