Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Effectively Parameterize Your Simulink Models

 Have you ever picked up someone else’s model only to discover that all of the model parameters were hardcoded. If you wanted to change the sample rate, you had to go on an Easter egg hunt to find everywhere the sample rate was defined and change it, one painful location at a time. Or, perhaps you tried to run someone else’s model only to discover that certain parameterized variables like “Fs” were undefined? Now you have to ask the model creator to send you another file for creating the model variables. 


This video shows one way to minimize or eliminate such problems. This approach involves parameterization via model callbacks. A callback is MATLAB code called under certain model conditions, e.g. when the model opens. A common tendency for new Simulink users is to hardcode parameters directly into a given block, e.g. setting the gain to “3” instead of “k1”. Hardcoding, while handy at times, is both cumbersome and error prone as the model grows in scope. Many times the Simulink model creator uses a MATLAB script to assign variables used by the moel. This is a step in the right direction but then users of the model are still forced to recall which script to run and then actually run it as a manual step. Sometimes this initialization script was never shared and the user is left none the wiser. 


This is where model callbacks come into play. Consolidate variable initialization into one script or function which attaches to the model as callback code. And depending on when and what conditions you want this script called, you place it in the appropriate callback slot. This makes model scaling and sharing far easier. The more we can avoid hardcoding and relying on human memory to kick off repeatable tasks, the better off we all are. 


No comments

Popular Posts

Followers