如何在MATLAB中声明代码生成的变量类型
考虑C代码中的以下变量声明:
Counter_Type counter_var;
这是一个C代码,它是用特定类型counter_type
定义的counter_var
。
我的问题是:如何声明一种变量类型,该变量类型在simulink中使用的MATLAB函数内部使用,生成的代码生成了使用该特定类型的变量。
例如,考虑以下代码,这是一个简单的奇数加法器,用matlab编写为matlab fucntion:
function Sum = sum_oddfcn(N)
Sum = 0; count = 1;
while ne(count,N)
if mod(count,2) ~= 0
Sum = Sum + count;
end
count = count + 1;
end
end
现在我想知道是否有一种方法可以声明count
在上述功能中声明的变量为使用custom_type
变量生成。
Consider the following variable declaration in C code:
Counter_Type counter_var;
It is a C code that a counter_var
is defined with a specific type Counter_Type
.
my question is: How it would be possible to declare a variable type which is used inside a MATLAB function in Simulink lead the generated code generates that variable with that specific type.
For instance consider the following code which is a simple odd number adder written in MATLAB as a MATLAB fucntion:
function Sum = sum_oddfcn(N)
Sum = 0; count = 1;
while ne(count,N)
if mod(count,2) ~= 0
Sum = Sum + count;
end
count = count + 1;
end
end
Now I want to know if there is a way to declare the count
variable declared in the above function to be generated with a type of Custom_Type
variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在MATLAB函数中使用添加参数,并在基本工作区中定义数据类型。
you can use add parameter in matlab function and define datatype in base workspace.