Defining function arguments using Assert function for code conversion to C++

2 次查看(过去 30 天)
What is the proper syntax for using the assert command to define the function arguments in my Matlab function below from which I want to generate C++ code using Matlab Coder? Below I give the beginning of such a code and as far as I know how to do successfully.
An example of my desired structure would be:(This section is not part of the code)
acme_employees.employeeID = [1 2]
acme_employees.name(1) = 'Bob'
acme_employees.name(2) = 'Renee'
acme_employees.resume_path(1) = 'c:\resumes\bob.doc'
acme_employess.resume_path(2) = 'c:\resumes\renee.doc'
Note! - The code begins here
function numEmployees = numEmployees_count(acme_employees)
%#codegen
assert(isstruct(acme_employees));
assert(isa(acme_employees.employeeID,'double'));
assert(all(size(acme_employees.employeeID) == [inf 1]));
  1 个评论
Arnab De
Arnab De 2013-2-12
This code works for me. It generates a structure with a single field named employeeID which is a variable-sized, dynamically allocated array of doubles. Is this what you want? Of course, you need to add asserts for other fields. Are you getting any error from codegen? If yes, which version of MATLAB are you using?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by