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