How to implement this c-code: if(Flag == 1) {Flag = 0;} ?
Mostrar comentarios más antiguos
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!
Respuestas (1)
Fangjun Jiang
el 14 de Oct. de 2011
0 votos
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 comentarios
Charles Wang
el 14 de Oct. de 2011
Fangjun Jiang
el 14 de Oct. de 2011
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
el 17 de Oct. de 2011
Fangjun Jiang
el 17 de Oct. de 2011
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
el 18 de Oct. de 2011
Charles Wang
el 26 de Oct. de 2011
Fangjun Jiang
el 26 de Oct. de 2011
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
el 31 de Oct. de 2011
Fangjun Jiang
el 31 de Oct. de 2011
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
el 1 de Nov. de 2011
Fangjun Jiang
el 1 de Nov. de 2011
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
el 14 de En. de 2019
Try with connecting Unit Delay(1/z) block and take the feedback.
Categorías
Más información sobre Simulink Functions en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!