How to initialize variables in Stateflow?

조회 수: 60 (최근 30일)
Akash Menon
Akash Menon 2018년 12월 10일
댓글: Cameron Ackroyd 2023년 4월 4일
Hi so according to the attached image I have some issues- I tried running it and it gives me an error saying that the variable 'instance' and 'k' aren't initialised.
The thing is with every input into the default state- I do not want these variables initialised. I only want them to have an initial value at the start of the simulation- from then on the values of 'k' and 'instance' will be handles by the consitions I have programmed into the other states.
But the thing is that with every iteration the code begins at the default state- unless I initialise it there- it doesn't work- but if I initialise it there- it will initialise the variables in every iteration- which I do not want.
I need to use temporal logic later on to build on this- so I cannot write this script as a matlab function either. I tried setting these variables as a local, parameter etc. but I'm not really sure how to set it correctly- the documentation seems a bit general- not sure how to apply it to this case- any ideas would be welcome!
Many thanks!
algorithm_freq_counter.PNG

답변 (1개)

Manjunath Bhimalli
Manjunath Bhimalli 2019년 1월 16일
Hey Akash,
got your issue.
Try something below it should work.
Take one extra input to stateflow 'initCondtn' from outside and assign it 0 via unit delay block and in stateflow create one more state as shown before doing the actual required stuff.
1st path will only gets activated during the 1st iteration because in the second sample time it will be zero the transition to your main logic state should pass unconditionally via 2nd path.
  댓글 수: 2
Akash Menon
Akash Menon 2019년 1월 31일
Wish I could try this but I figured a work around which employed putting the required states within a time window that would cause the loop to be restrained in that state and after the time window elapsed it would reinitialise.
But seems like a nice thought to try it if I come across it again in the future!
Thanks for your response! I will keep it in mind to try it out if I have to use it again.
Cameron Ackroyd
Cameron Ackroyd 2023년 4월 4일
Hi Manjunath,
This fixed an issue I had, thanks for your suggestion.
(I had to have initial condition in the unit delay block set to 1)

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

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by