value that increase along with changing value by manual switch block simulink using embedded matlab function
显示 更早的评论
hi all
i just wanna ask,how we do the increasing value by changing manual switch in simulink??
for example: i have manual switch, with 2 constant block connect to it, first signal= 1 , second=0. i have calculation that everytime we change value in manual switch the system will add 10 to the current signal.
how we do it with embedded matlab function??
1 个评论
Walter Roberson
2011-7-15
Duplicate is http://www.mathworks.com/matlabcentral/answers/11705-value-that-increase-along-with-changing-value-in-manual-switch-block-simulink
采纳的回答
更多回答(4 个)
Walter Roberson
2011-7-15
1 个投票
Please do not open duplicate questions; it just ends up duplicating efforts.
You can edit your previous question if needed.
Kaustubha Govind
2011-7-15
FWIW, here's an EML implementation:
function y = mycounter(u)
%#eml
persistent count;
persistent prevInput;
firstInput = false;
if isempty(count)
count = 0;
end
if isempty(prevInput)
prevInput = 0;
firstInput = true;
end
if ~firstInput
if (prevInput ~= u)
count=count+1;
end
end
prevInput = u;
y = count;
end
Fangjun Jiang
2011-7-15
1 个投票
Okay, feed the switch output signal to the triggered subsystem, still choose "either". Also, feed the switch output signal to an Inport of the the triggered subsystem, multiple it by 10, then feed it to an Integrator block. Did not verify. Should work. Try it yourself.
3 个评论
Luhur
2011-7-15
Fangjun Jiang
2011-7-15
Then change the sample time of the Integrator block to be -1.
Luhur
2011-7-16
Luhur
2011-7-15
0 个投票
4 个评论
Fangjun Jiang
2011-7-15
It certainly can be done. It is different though. Your original intention was to increase the counter by 10 every rising or falling edge of your switch output. This one, how do you increase if the switch output is 1? Increase 10 at every time step? Or there is something else trigger the increase?
Luhur
2011-7-15
Fangjun Jiang
2011-7-15
If 1 then current value is increased by 10. Increased only once, or every time step as long as the switch output is 1?
Luhur
2011-7-15
类别
在 帮助中心 和 File Exchange 中查找有关 Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!