필터 지우기
필터 지우기

How to store dynamically an array in a For iterator Simulink Subsystem

조회 수: 9 (최근 30일)
patr chri
patr chri 2020년 5월 28일
편집: patr chri 2020년 5월 28일
Hello,
I have this simple system:
The code in the function is:
function a = fcn(iteration,a)
a(1,iteration) = iteration;
end
The outside Simulink layer is the following (a is initialized as a = zeros(1,5)):
The loop is a
for i = 1:5
and I want to store the iterator in an array (ie [1 2 3 4 5]), but for some reason Simulink initializes the array at every iterator step for a single time step, so I can only see the last value.
I have tried many different combinations, but nothing works. Do you know how I could do it?
Thank you in advance,
Christos

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 5월 28일
I know this might be a simple example behind your real need. But this is unnecessary.
  1. The for-loop can be implemented inside the MATLAB Function block.
  2. Keep in mind, the simulation runs along the time. At every time step, the whole model runs. The MATLAB Function block is executed at every time step. So if you have a for-loop inside the MATLAB Function block, the output is propagated after the for-loop is finished.
  3. Most likely, you don't need the for-loop inside the MATLAB Function block. Code can be written to deal with the 1x5 vector input directly.
  댓글 수: 1
patr chri
patr chri 2020년 5월 28일
편집: patr chri 2020년 5월 28일
The for-loop in a MATLAB function block will not allow me to solve a set of equations which are difficult to be written in MATLAB code and they have to be solved inside the iteration, that's why I think I have to to stick up to the "For iterator subsystem".
I found that there is a Tapped Delay block which can help me to store something in some kind of vector, but still I face non-desirable results that I should probably address in a different question.

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by