value that increase along with changing value by manual switch block simulink using embedded matlab function
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Fangjun Jiang
2011년 7월 15일
Do you have to use EML? If not, it could be done easily in Simulink using a trigger subsystem. Type "sldemo_counters" to open the demo model, connect your manual switch block output to the triggered subsystem. Inside the system, change the trigger from "risgin" to "either", change the constant from 1 to 10 then you got it.
추가 답변 (4개)
Walter Roberson
2011년 7월 15일
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
댓글 수: 2
Fangjun Jiang
2011년 7월 15일
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일
댓글 수: 4
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!