How to pass a structure containing array fields to an embedded matlab function?

2 views (last 30 days)
I am trying to build a framewwork which allows to embed matlab functions into a C++ environment. To minimize the effort to integrate a new matlab function into the C++ environmen I want all functions to have a unique interface for exchanging parameters with the matlab function which is the same for all functions to be used. This interface could be realized by varargin / varargout, by a named argument list or by passing a single structure array which contains fields describing the parameters ('Name', 'Unit', 'Type', 'Value').
As far as I understand I can not use varargin / varargout, or a named argument list for the top-level embedded matlab function. Passing structures as input does work. Example:
function S = structTest(S) %#eml
assert(isstruct(S));
assert(isa(S(1).a, 'double');
S(1).a = 1; % Field 'a' is a scalar value!
My problem is that I need to be able to pass arrays in the above mentioned 'Value'-field of the structure which does not seem to work for input structures (creating structures with array fields inside the embedded matlab function and returning them is no problem).
Example:
function S = structTest(S) %#eml
assert(isstruct(S));
assert(isa(S(1).a, 'double');
S(1).a(1) = 1; % Field 'a' is an array!
S(1).a(2) = 2;
does not compile. Error message: ??? Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
Trying to let the coder now that field a is an array does not work either (at least I do not know how to do it). E.g.
assert(numel(S(1).a) == 10);
returns the same error message.
Questions: Does anybody have an idea how to pass arrays in structure fields? If not: Any othe ideas how to create a generic interface for embedded matlab functions?
Scope: Using Matlab R 2010b, no Simulink !!

Answers (0)

Community Treasure Hunt

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

Start Hunting!