Matlab Function block: how to output the result in different instants of time

Hello everybody,
is there a way to output the result of a Matlab Function block in Simulink in different instants of time? In other words, assuming that my function block contains this trivial code, and suppose to link it to a display block:
input = 5;
for i = 1:10
pause(1); % I know, it doesn't work, I write it just for explain that I want to output the result of the computation every 1 sec
output = i*input;
end
if I run a simulation on Simulink, it outputs directly 50. I would read on the display 5...10...15......50, where ... it stands for "1 sec pause". How can I do it?
Thanks.

 채택된 답변

The MATLAB Function block is called once at each time instance so to do what you want, you need to have a state that updates at each time hit. Here is a simple example of that using persistent variables
function y = fcn
%#codegen
persistent u
if isempty(u)
u = 0;
else
u = u+1;
end
y = 5*u;
You should set the simulink solver to discrete with fixed step, and you can set the time step to 1.
HTH

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품

질문:

2014년 7월 21일

댓글:

2014년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by