File Exchange

image thumbnail

Simulink Model String Replacement

version (2.14 KB) by Will Campbell
replace a string in Simulink object names with another


Updated 01 Sep 2016

View License

mdl_strrep is a utility to identify blocks and other Simulink components that contain a particular string in their name.
MDL_STRREP(OBJECT,S1,S2) replaces all occurrences of the string S1 in the name of a Simulink object and its children with the string S2. This enables the user to remove undesired characters in bulk or replace phrases when the model is used in a different context.

MDL_STRREP(OBJECTS,S1,S2) replaces all occurrences of the string S1 in the name of all Simulink objects defined in a cell array. The function will not include any children of the objects defined. This enables the user to fully specify the objects they wish to manipulate.

mdl_strrep(bdroot,' ','_')
replaces spaces in all blocks of current model with an underscore

cr = sprintf('\n');
removes any carriage returns in current block's name and any of its components if it's a subsystem

myblocks = find_system(bdroot,'BlockType','Scope');
finds all Scopes in the model and replaces the phrase "Scope" with "Probe"

Cite As

Will Campbell (2021). Simulink Model String Replacement (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!