Very few projects start off with a clean slate; the majority have some body of existing text-based code (C/C++/Asembler) which needs to be either translated or wrapped into the Model-Based Design environment. For the cases where translation is the desired path, the objective should be the translation of the essence (e.g. requirements) not the content.
Why translate essence, not content?
First, every programing language has unique constructs which may or may not be directly replicable in other languages. Because of this, a common failure mode is to try and directly replicate coding patterns in the MBD environment.
Second, when you translate the based on the requirements you have the opportunity to improve upon the existing code.
There is a function for that…
It is common with text-based algorithms to implement basic functions such as table look ups, integrators, etcetera. While in some edge cases the text-based implementation is more efficient this is less common with the growing maturity of Model-Based Design tools.
Further, the small efficiency gains from the existing implementation are frequently less important than the clarity found by using built in blocks.
It is really a…
In text based languages truth tables and state machines are implemented as either a series of if/then/else or switch/case statements. Within MBD environment both truth tables and state machines have direct implementations.
Pushing things too far…
The final note, there are some areas where text based modeling makes the most sense. Generally, this is in the area of long complex equations. While they can be rendered in block form they are more easily read in text form. With that in mind, I recommend using MATLAB blocks for longer equations.
The image above, the Pythagorean theorem, is relatively simple. Yet even it would be more easily read as
C = sqrt(A^2 + B^2)
Final thoughts (part 1)
When translation occurs it is important that the new implementation is validated against the behavior of the existing code. Failure to do so can result in larger system level errors.
Final thoughts (part 2)
In my translation example, I used the simple phrase “I have the cutest cat in the world” I submit the following images to back that claim up