Simulink:使用多电平总线信号执行数学运算 [英] Simulink: Perform math operations with multilevel bus signals

查看:121
本文介绍了Simulink:使用多电平总线信号执行数学运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,将多级总线信号求和在其层次结构内的最低级别上进行汇总。

,而不会丢失总线信号结构。



MWE



例如,在下面的MWE中,

会自动将总线信号汇总到最低级别,< br>
但是,通过Add块后总线信号丢失。



会生成矢量信号。





我更愿意使用一种产生以下结果的方法:



红色+蓝色=紫色



或更具体地说:



red。[abc]。[ 1 2] +蓝色。[abc]。[1 2]->紫色。[abc]。[1 2]



其中



purple.b.3 = red.b.3 + blue.b.3



等。

解决方案

据我所知,对总线信号进行数学运算的唯一可能性是使用MATLAB Function模块。请注意潜在的不良性能!



要使用MATLAB Function模块,请首先生成一个匹配的总线对象,并确保两个总线创建者将a / b / c合并分配输出该总线对象。这样做会出现错误,因为1和2不是有效的字段名称,我将它们更改为x1和x2。



在下一步中创建MATLAB Function模块。


I am seeking a method to sum multilevel bus signals
at the lowest level within their hierarchy
without loss of the bus signal structure.

MWE

For example, in the MWE below,
the bus signal is summed at the lowest level automatically,
however, the bus signal is lost after passing through the Add block.

A vector signal is produced instead.

I would have preferred a method which yields:

red + blue = purple

or more specifically:

red.[a b c].[1 2] + blue.[a b c].[1 2] --> purple.[a b c].[1 2]

where

purple.b.3 = red.b.3 + blue.b.3

and so forth.

解决方案

To my knowledge, the only possibility to do math with bus signals is using a MATLAB Function block. Be aware of the potentially bad performance!

To use a MATLAB Function block, first generate a matching bus object and make sure the two bus creators mergin a / b / c each are assigned to output this bus object. Doing so you will receive an error because 1 and 2 aren't valid field names, i changed them to x1 and x2.

In the next step create a MATLAB Function Block. Set the two inputs and one output to your previous defined bus object. Paste the following code:

function y = fcn(u, v)
%#codegen

y.a=innerplus(u.a,v.a);
y.b=innerplus(u.b,v.b);
y.c=innerplus(u.c,v.c);
end

function y=innerplus(u,v)
y.x1=u.x1+v.x1;
y.x2=u.x2+v.x1;
end

这篇关于Simulink:使用多电平总线信号执行数学运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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