简体   繁体   中英

Using if function in MATLAB Simulink

I have created the following block diagram on Matlab Simulink. It should give OUT1=1 OUT2=0 when INPUT>=0 and OUT1=0 OUT2=1 when INPUT<0. But it does not give the expected results. What is the reason for that. Any advice to make it work correctly would be appreciated.

在此处输入图片说明

The behaviour you are seeing can be explained by noting the following:

  • The output from the If Subsystem acts like an enable signal.
  • By default, the Output Ports of an If Action Subsystem are set to hold their values when the (sub)system is disabled.

This can be changed by going to the parameters dialog of the Output Port (within the If Action Subsystems) and changing the Output when disabled property to reset . You'll also want to change the default value to zero.

This if function block thing didn't work. So I come up with a different approach to get the result I wanted using the sign block. Solution is posted below. Thank you for everyone for trying to help.

在此处输入图片说明

In many cases an IF is translated to a switch . You calculate cases and select the one which is intended. Here you could connect a constant [1 0] and a constant [0 1] to the first and third input and the sign block from your solution to the second input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM