Using RTW to generate reusable functions with different parameters

Hi all, I hope this isn't too dumb of a question for this newsgroup as I usually enjoy lurking around.
My question center's around RTW and the auto generation process.
I'm currently using RTW in 2007b and have lot of similar subsystems in my model, similar enough such that the only thing different is the parameter's passed to them (in integration systems it's the saturation limits, in deadzone/relay systems it's limits to trigger these effects).
For example, I have four discrete integration subsystem with the same surrounding blocks, but each of the four integrators themselves have different saturation limits.
I'm aware that if the subsystem's were identical, one could simply force them to be atomic and classify them as reusable functions (or auto) to create one function in which each of the four instances call it. However, if something small, like the saturation limits on the discrete integrator for example, are different is it possible to still create one function to be used in each of those instances but have the limits be variables that get passed actual values from the function call?
I've come up with a few ways to trick the auto generator to do this on a case by case basis, but was wondering if there was a cleaner way to do it.
I appreciate the comments!

 Accepted Answer

Hi,
my suggestion would be to turn that subsytem into a Masked Subsystem: right click and select entry "Mask subsystem". Then select "Edit mask" and you can "design" your mask. More or less you only specify the parameters that you pass into the subsystem (saturation limit). In the saturation you use instead of the value (42.0) a variable (e.g. LIMIT). On the mask you specify the variable to be "LIMIT". When later you double click on the block, you can enter again 42.0 for the limit. Does this help?
Titus

1 Comment

Titus, thank you very much!; I wasn't aware how powerful the masking was when it came to RTW and code generation. As for right now this answered my question perfectly, thank you! It's great that it even works with data objects as well.
I'll have to do some more testing but it seems like this is it!
Chris

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!