Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codegen and scalar struct argument

Tags:

matlab

Codegen commands like this:

codegen -config:dll ep1 -args single(0) ep2 -args {0,0}

are easy for functions like this:

function y = ep1(u) %#codegen
y = u;

function y = ep2(u, v) %#codegen
y = u + v;

I am just wondering how to define scalar struct arguments. Let us assume that the above argument u should look like this (i.e. consist of 2 fields - one char and one double):

u.FirstName = 'Loren';
u.Height = 150

PS:

Just found something like this:

s = struct('a',42,'b',4711);
codegen topfun.m -args { s }

would this be a solution? I believe, this is a definition by example.

like image 202
cs0815 Avatar asked Aug 30 '26 11:08

cs0815


1 Answers

This seems to work for me:

codegen -report -config:dll ep1 ...
                            ep2

The actual 'function signature' (and thus scalar struct) can be defined in the function like this:

function [bla] = ep1(parameters)
%#codegen

assert(isstruct(parameters));
assert(isa(parameters.x1,'char'));
assert(size(parameters.x1, 1) >= 1);
assert(size(parameters.x1, 1) <= 1024);
assert(isa(parameters.x2,'double'));
...

Problem I have is that I seem to have to define all the parameters in the parent functions even-though I do not use the parameter in the parent function.

Looking at the stuff above. Let us say ep1 is the parent function of ep2 and ep1 does not use parameters.x2, I still have to assert it in ep1.Hope this makes sense.

like image 181
cs0815 Avatar answered Sep 03 '26 09:09

cs0815