Simulink Threshold with action
显示 更早的评论
I would like to create a simulink model that basically takes an input, lets say 2.5, and check if this value is between 6.5 to 8.5. Once checked, if below this range, then it must add 1 to the initial input. If it is betwen this range, all it needs to do is display the output that falls between the 6.5 to 8.5 range. If possible, I would like for it to show how many iterations it took to get between range.
回答(2 个)
Naturally, I would expect that the input signal evolves over time and that the thermostat-like controller performs a switching action to maintain the signal within a specified band.
However, the way you described the requirement suggests a discrete event. Consequently, it is relatively straightforward to calculate the number of iterations required mentally.
numIteration = 0;
input_Signal = 2.5;
desiredState = 6.5;
%% as if you would calculate in mind
number_of_iterations = desiredState - input_Signal
%% switching action
while input_Signal < desiredState
switchAction = 1; % constraint of the controller
input_Signal = input_Signal + switchAction;
numIteration = numIteration + 1; % counter
end
input_Signal
numIteration
Walter Roberson
2025-2-22
0 个投票
Initialize the input signal. "While" the current signal is less than the desired state, add the increment to the signal and increment a counter. When the condition becomes false, read out the counter.
类别
在 帮助中心 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!