Executing full MATLAB code within Simulink Blocks

An easy way to execute complicated functions in Simulink is to use the Embedded MATLAB Function block. When you insert one of these blocks it creates a MATLAB file that is contained within the Simulink model block. The issue with this block is that only a subset of the full MATLAB language is available within an Embedded block. The simple solution to this problem is the function eml.extrinsic which sets certain functions to execute externally.

Example:

eml.extrinsic('myfunction');
[outputa outputb] = myfunction(inputa, inputb);

The function names within the extrinsic call will be set to run within MATLAB instead of Simulink. Now functions like tf and ss can be used!

Another Embedded MATLAB tip is to use ‘*1i’ to represent complex numbers. (This is mentioned in the MATLAB documentation but looks like ‘li’.)

References:
http://www.mathworks.com/help/toolbox/simulink/ug/f6-106261.html

Advertisements

Using LaTeX for Equations

In the technical reports I find myself writing these days there are usually a lot of equations and I have found LaTeX to be the best for this. I usually use the Sitmo online editor. The following post is a reference for some of the LaTeX commands I can never remember (to be appended)

  • Matricies
    example:
    LaTeXExample1Matricies
    code:

    \frac{d}{dt}
    \left( {\begin{array}{cc}
    \omega \\
    I \\
    \end{array} } \right)
    =
    \left( {\begin{array}{cc}
    -\frac{B}{J} & -\frac{K}{J} \\
    -\frac{K}{L} & -\frac{R}{L} \\
    \end{array} } \right)
    \left( {\begin{array}{cc}
    \omega \\
    I \\
    \end{array} } \right)
    +
    \left( {\begin{array}{cc}
    0 \\
    \frac{1}{L} \\
    \end{array} } \right)
    E


    example:

    code:

    \left[ \begin{array}{ccc} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{array} \right]
    \

    example:

    code:

    \left[ \begin{array}{c} y_{1} \\ y_{2} \end{array} \right] =
    \left[ \begin{array}{cc} G_{11} & G_{12} \\ G_{21} & G_{22} \end{array} \right]
    \left[ \begin{array}{c} u_{1} \\ u_{2} \end{array} \right]