MATLAB Answers

How to update values ​​in Simulink

11 views (last 30 days)
Shunsuke kishi
Shunsuke kishi on 18 Dec 2019
Answered: Mark McBroom on 29 Dec 2019
I am creating a simulation with Simulink. I originally wrote the code in MATLAB script, but it is necessary to block it, and it is blocked mainly using MATLAB function. I want to use the value calculated in the previous loop in the next loop. How should I do that? Here is a simple block. Specifically, a wants to take a value from "initial_value" in the first loop, but wants to update the value from "calculate" in the subsequent steps.

  0 Comments

Sign in to comment.

Answers (2)

Fangjun Jiang
Fangjun Jiang on 18 Dec 2019
All you need is to declare "a" as a persistent variable.
doc persistent

  1 Comment

Shunsuke kishi
Shunsuke kishi on 19 Dec 2019
Sorry, I forgot to post the photo. I want to use "a" output by "calculate" in the next loop as shown in this photo. When written in code, it looks like this:無題111.png
a = 0;
a0 = 0.1;
while(1)
a = a + a0;
end

Sign in to comment.


Mark McBroom
Mark McBroom on 29 Dec 2019
It would be easier to do this with basic simulink blocks. See attached screen shot. Unit delay block by default has initial value of a=0 but can be set to non-zero vaue.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019b

Translated by