How to implement this c-code: if(Flag == 1) {Flag = 0;} ?
이전 댓글 표시
I used a signal (this is what I needed) for Flag at an input port of stateflow, but Flag is not recognized inside the stateflow. If I add an input data in the stateflow, it will not be allowed to change the value (through a transit with a statement {Flag=0;} inside the stateflow).
Please help. Thanks!
답변 (1개)
Fangjun Jiang
2011년 10월 14일
0 개 추천
This is one of the difference between C and Simulink. In C, you can re-use the variable name. In Simulink, the signal name represents the data flow. You can't re-use the signal name. You have to declare an output for the Stateflow and then assign value accordingly.
댓글 수: 12
Charles Wang
2011년 10월 14일
Fangjun Jiang
2011년 10월 14일
You certainly can use Flag1 to carry the value of Flag. But you can't add Flag as an output since it's already an input.
Don't think Flag or Flag1 as variables. They are signals, as the signals in a circuit board.
There won't be any problem for code generation. The code might just not be the same as you would write it manually.
Charles Wang
2011년 10월 17일
Fangjun Jiang
2011년 10월 17일
In Stateflow, if you define Flag as input, you can not do "if(Flag == 1) {Flag = 0;}".
If you define Flag as output, you can do "if(Flag == 1) {Flag = 0;}".
Charles Wang
2011년 10월 18일
Charles Wang
2011년 10월 26일
Fangjun Jiang
2011년 10월 26일
Each block in a subsystem needs to have a unique name so you can't have multiple blocks named as Flag in a subsystem, but you could have many Inport or Outport named as Flag in a model but in different subsystems. A signal has only one source but can be used in many destinations. Goto and From blocks are for connection. You can have only one Goto block (source for the connection) that has "Flag" as the goto tag, but you can have many From blocks (destination for the connection) that have "Flag" as the goto tag. For your purpose, you many need to consider the Memory Store/Read/Write block.
Try to use Simulink in its natural way, not to twist it trying to match the C code behavior. Sometimes you have to accept that apple and orange are different.
Charles Wang
2011년 10월 31일
Fangjun Jiang
2011년 10월 31일
If you are using Memory Store Write block, why do you still need the Goto and From block? You can use Memory Store Write block wherever need to write and use the Memory Store Read block wherever you need to read. Check the help of Memory Store Memory/Read/Write block, there are different options regarding the scope of the memory.
Charles Wang
2011년 11월 1일
Fangjun Jiang
2011년 11월 1일
You are right. Port name is used to identify the port block. The generated code will not necessarily use port name for variable name.
Manjunath Bhimalli
2019년 1월 14일
Try with connecting Unit Delay(1/z) block and take the feedback.
카테고리
도움말 센터 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!