Function Block in Simulink always runs last line of an if statement, even if the statement is false. Possible block bug?

1 view (last 30 days)
In this particular section of a code block for a chiller controller, I am telling the chiller to output power and flow numbers from previous step if the chiller is running and within the control band. However, it kept setting the "Flow_out" value to "Flow_Last", even when "Chiller_Last" = 0. Code:
Now, when I put a breakpoint here, and confirmed "Chiller_Last = 0":
I step, and it jumps directly to this line, skipping over the Chiller_PWR line, and executes it:
Now check this out, if i add "if 1 == 0", and nest this loop:
It STILL jumps directly to this last line, and executes it:
I've just added something stupid and incosequential to be the last line that gets executed no matter what the if statement says, so I found a work around. I figured, though, that I would put this here in case anyone else had this issue.
  1 Comment
Sai
Sai on 25 Jan 2023
Hi,
I tried to reproduce the issue, but it is working fine with me. Can you please share the MATLAB release and version you are using along with the code so that I could reproduce the issue and investigate furthur?

Sign in to comment.

Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!