Simulink elementwise switch for vector sample

8 次查看(过去 30 天)
Hi all,
my probelm:
a, b, and c all are of size [nx1]. a contains data, b is a control-vector and c the output.
I want to implement a logic into my simulink system which functions as follows:
Output should initially be zeros(length(a)). If b(1) turns to true -> c = [a(1), zeros(length(a)-1)]. So basically, for each input-element of a, there is one control-element in b. If the element-specific control-element truns true, the output of the system should become a for that specific element and remain 0 for the rest. The size of n is constant during each simulation but can be initiated differently.
Moreover, once an elemnt of c becomes a, it should remain so until the rest of the simulation even in case b turns false during that time.
I am new to simulink so this is maybe an easy question but even so I am getting a bit frustated at this point. Thank you a lot in advance!

采纳的回答

Yingye Gan
Yingye Gan 2019-3-7
Hi Alexandros,
In case that I misunderstood your question, I did not provide the complete solution here. But you may find the following tips helpful.
- Tip 1: Use For-each subsystem to operate on array input elementwisely.
C1.PNG
- Tip 2: Use blocks from 'Logic and Bit Operations' and 'Switch' block to perform logical operations. In my solution, inside of the For-each subsystem, a switch block is used to set the output (c) value to be either 0 or value in input a.
C2.PNG
- Tip 3: Use blocks with states to record previous running status. Unit Delay block is adopted in my solution here to record the value of the rectified control vector 'b_rectify' from the previous run. This vector ensures that the element values remain '1' once it has previously been set to '1' by performing logic or operation with 'OR' block. Make sure yout set the initial condition of Unit Delay block to be the same as the initial value of vector b.
C3.PNG
- Tip 4: In the case where control vector is from external source, use 'In1' block to provide a input port. Make sure that the data (vector b) feed to this port has the same dimension as vector a.
C4.PNG
Or you can use 'Matlab Function' block and 'S-Function' block to implement your own logic. You should be able to find more instructions and examples in Simulink Documentation,
Hope these tips serve your purpose.
  4 个评论
Alexandros Papadopoulos
@madhan ravi, I think they're constant blocks with [1 2 3] and [1 0 1] as values.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discontinuities 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by