How do i make a switching function?

조회 수: 1 (최근 30일)
Roy Hauge
Roy Hauge 2015년 4월 29일
답변: Roy Hauge 2015년 4월 29일
I am trying to make a switching function for a simulink function block. Currently and faulty:
function y = Switch(SOC,Input,Launch,Charge,A)
%#codegen
y = A;
if ((Launch == 1), (SOC ~= Input))
y = Charge;
else
y = A;
end
I want the output y to be the same as A unless the Launch is 1 and SOC is different from Input, in that case I want y = Charge. Another block takes care of comparing SOC and Input driving the Charge current.
How do i modify this code to get the correct switching. As an addon the y = Charge should hold until SOC = Input and then reset back to y = A;

답변 (1개)

Roy Hauge
Roy Hauge 2015년 4월 29일
Syntax error replaced , with && in if statement.
function y = Switch(SOC,Input,Launch,Charge,A)
%#codegen
y = A;
if ((Launch == 1) && (SOC ~= Input))
y = Charge;
else
y = A;
end

카테고리

Help CenterFile Exchange에서 Code Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by