How to create dynamic goto tag names in Simulink?

19 views (last 30 days)
I am developing some libraries and I want that most of the signals of the components comunicate with other components without visual links, so that I am using global GOTOs. My idea is that the final user will be able to specify the FROMs of a component in the component mask. (In anyone know other way to do that without global GOTOs it would be great).
The problem is that if I insert two times the same component from the library I will get two GOTOs with the same name. As the name of the component automatically changes ("Component", "Component1", "Component2"...) i would like to add a refference to the component's name in the GOTO tag name, something like:
Tag name: strcat(gcb,'_goto_name')
where gcb is a function that gets the block's path.
Is that possible? How could I do it? If not I think I could also activate a callback with code to do that everytime the name of a system changes...
Thank you all

Answers (1)

Sebastian Castro
Sebastian Castro on 9 Apr 2015
You should be able to make a self-modifying block using Block Callbacks.
To do this, you can right-click the block and select Properties, then go to the Callback tab. In one of those callbacks, probably "NameChangeFcn", you can add the following code:
blkName = get_param(gcb,'Name');
set_param(gcb,'GotoTag',[blkName '_goto_name']);
- Sebastian
  1 Comment
Marina
Marina on 9 Apr 2015
Thanks!
I have tried it with Simulink Callbacks CopyFnc and NameChangeFcn and it works.
Just to note that if the component has a mask, the name of the tag has to be modifyable fom the mask and what you should modify is the mask value, not the Goto Tag name.
Also, when the Goto is modified the Froms also need to be modified as Sebastian explains in http://www.mathworks.com/matlabcentral/answers/194890-parameterize-simulink-goto-and-from
Marina

Sign in to comment.

Categories

Find more on Interactive Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!