Did you ever get an error like this?
??? Invalid Simulink object name: model_f14/Controller.
Of course. Anytime you have a typo in a call to get_param or set_param, you will get this message. This is very frustrating, especially when you look at the model, and see the block with the very same name!
To understand why this was happening, I had to compare the string I was using to the name of the block from using gcb (get current block).
>> s1 = 'model_f14/Controller'
s1 = model_f14/Controller
>> s2 = gcb
s2 = model_f14/Controller
ans = 0
The string from gcb looks the same, but then I noticed the size of the signals in the workspace.
The block has a trailing white-space character! Where did this space come from? The space was probably an accidental keystroke while naming the subsystem. This can happen to anyone, so how could you detect it in your model?
Model Guidelines and Model Advisor
Most teams doing Model-Based Design for production work eventually implement modeling guidelines/standards. Modeling standards make it possible for teams to make components that work well together and look like they were made by the same team. Often, modeling standards include rules about what blocks to use, what settings to use, how to architect the model, how to layout the diagram and naming conventions.
The MathWorks Automotive Advisory Board assembled modeling guidelines for control algorithm modeling and many were implemented as Model Advisor checks (as part of Simulink Verification and Validation). The group of checks I need are the Naming Convention checks under the Modeling Standards for MAAB task.
When I selected the Check subsystem names and clicked Run This Check, I got the report you see above. Notice it flagged the model_f14/Controller block as containing an incorrect character. Incorrect characters are those not in the list of allowed characters:
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 _
There are a few standards related to Naming Conventions:
- ar_0001: Filenames
- ar_0002: Directory names
- jc_0201: Usable characters for Subsystem names
- jc_0211: Usable characters for Inport blocks and Outport blocks
- jc_0221: Usable characters for signal line names
- jc_0231: Usable characters for block names
- na_0014: Use of local language in Simulink and Stateflow
For a moderate to large model, you can imagine the time this type of model check would save you.
What are your modeling standards? Do you run the Model Advisor to check that models conform to the standard? Leave a comment here with your thoughts.
5 CommentsOldest to Newest
I hate the “Invalid Simulink object name” error, the last time that happened to me was yesterday, there was one space character in the block name, other errors I get often are caused by stuff like this
I don’t follow any model standard yet and also don’t use the Model Advisor but it would save me a lot of time!
@Paulo Silva – I used to have the very same problem with forward and back slashes. Somehow, I think I just got the right slash type habit.
Thanks for the pointer to ‘MAAB Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow’, http://www.mathworks.com/help/pdf_doc/simulink/maab_guidelines.pdf . Is there a short informal overview of these best practices that you could point to? Though I am glad to learn here to stop using spaces in my block names. Wish there was a command line to replace all the spaces with underlines.
1) The shortest overview of best practices that I’ve found: ‘MathWorks Automotive Advisory Board Checks’ in Simulink Validation & Verification Reference, http://www.mathworks.com/help/pdf_doc/slvnv/slvnv_ref.pdf or http://www.mathworks.com/help/toolbox/slvnv/ref/brlhc3t.html
2) Good tool for replacing all blanks in block names with underscores and other sorts of global replaces, http://www.mathworks.com/matlabcentral/fileexchange/26424-simulink-model-string-replacement
I am having a similar problem, my model used to be working fine but after removing some blocks that were no longer required the error “invalid simulink name: .” appeared. I tried building that portion of the model but keep having the same error.