codegen和标量struct参数 [英] codegen and scalar struct argument

查看:84
本文介绍了codegen和标量struct参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样的Codegen命令:

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;

我只是想知道如何定义标量结构参数.让我们假设上面的参数u应该看起来像这样(即由2个字段组成-一个char和一个double):

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.

推荐答案

这似乎对我有用:

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.

看上面的东西.假设ep1是ep2的父函数,而ep1不使用parameters.x2,我仍然必须在ep1中声明它.希望这是有道理的.

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.

这篇关于codegen和标量struct参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆