When I first began using Simulink, I was averse to the From and Goto blocks in the Signal Routing library. Years of writing Fortran (yes Fortran) had ingrained in me a deep aversion to "Goto." But I soon realized that the block had little to do with the questionable coding practice.
Under the proper circumstances, From/Goto combinations can be quite powerful in Simulink. They serve as invisible shortcuts for signals within the model. This enables the user to avoid signals crossing one another, a stylistic choice that can make a model harder to decipher. Of course you wouldn't want to exclusively use Froms/Gotos; that would also make for a cryptic diagram.
If you're looking for a good rule of thumb on when to use these blocks, the MathWorks Automotive Advisory Board (MAAB) produced a style guide that includes rules for From and Goto. Check out sections 6.1.14 and 6.3.5 for more information. Below is a screenshot of proper usage according to MAAB.
Once you get in the habit of using these blocks, you'll probably discover that management of them isn't quite as efficient as it could be. When you add a Goto block to your model, you invariably want a corresponding From block. That means you have to go to the Library Browser, find the From block, add it to the model, double-click on it to open the dialog, and associate it with the proper Goto tag. You may also want to color code the blocks to match one another.
Giacomo's contribution streamlines this entire process by adding an option to the menu when right-clicking on a Goto block. Selecting the menu option will create a corresponding From block with the appropriate tag. It will even make the aesthetics of the block (font, background color, size, etc) match its Goto partner. Now we can all be that much more productive!
Comments
Let us know what you think here or leave a comment for Giacomo.
By
Will Campbell
Will is an application engineer at MathWorks. Though an avid MATLAB fan, he typically supports users of Simulink within the aerospace industry. His favorite science text is Lectures on Physics by Feynman.
Hi friends i m working on project in which we are controlling the water levels of the tanks for that purpose we calculate the error between actual level and desired level and we are interested to optmie this error by using our own Genetic code which is ready with us.
GA code in matlab is having 3 files i.e.simu_ga.m(main script file),[testfunction.m and gacode.m are the sub function calls]
we have to excute this matlab code into simulink models
so frnds which simulink block is preferable and how we can give input to this code and send output of the code execution is sent to next simulink block.
so frns plz help us !!
Thanks!!!!!
Hi Sagar,
Thanks for your inquiry. I’m glad to see that you’re making use of Simulink and MATLAB in your project. If you would like to make use of your genetic algorithm code within Simulink, I would recommend the Embedded MATLAB Function, which can be found in the Use-Defined Function section of the Simulink library. Alternatively, you can leverage Level-2 MATLAB S-Functions.
Through use of the Embedded MATLAB block, you can create a skeleton function whose inputs and outputs become ports within Simulink. Your existing MATLAB functions can be invoked by use of the eml.extrinsic command. Bear in mind that your algorithm will be called every time step in Simulink. This may require reworking of your algorithm to accommodate Simulink.
Also be aware that there’s an I/O penalty every time Simulink and MATLAB communicate with one another. So while this will work as a great first step, the simulation may run slowly for your needs. Down the road, you may consider changing your MATLAB code to be Embedded MATLAB compliant. This will enable Simulink to convert the algorithm into C code for you and will make your simulation much faster.
Feel free to contact your local MathWorks representative if you have further questions. We would be happy to visit with you.
Cheers,
-Will
Leave a Reply
About
Brett & Jiro share their favorite user-contributed submissions from the File Exchange.
Hi Sagar,
Thanks for your inquiry. I’m glad to see that you’re making use of Simulink and MATLAB in your project. If you would like to make use of your genetic algorithm code within Simulink, I would recommend the Embedded MATLAB Function, which can be found in the Use-Defined Function section of the Simulink library. Alternatively, you can leverage Level-2 MATLAB S-Functions.
Through use of the Embedded MATLAB block, you can create a skeleton function whose inputs and outputs become ports within Simulink. Your existing MATLAB functions can be invoked by use of the eml.extrinsic command. Bear in mind that your algorithm will be called every time step in Simulink. This may require reworking of your algorithm to accommodate Simulink.
Also be aware that there’s an I/O penalty every time Simulink and MATLAB communicate with one another. So while this will work as a great first step, the simulation may run slowly for your needs. Down the road, you may consider changing your MATLAB code to be Embedded MATLAB compliant. This will enable Simulink to convert the algorithm into C code for you and will make your simulation much faster.
Feel free to contact your local MathWorks representative if you have further questions. We would be happy to visit with you.
Cheers,
-Will