Clear Filters
Clear Filters

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

2 views (last 30 days)
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 Comment
Arnab De
Arnab De on 12 Feb 2013
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?

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!