Create & Connect Viewer Programmatically

4 views (last 30 days)
Alessandro
Alessandro on 23 Nov 2017
Commented: Fabien Fellay on 30 Jun 2020
Hello, I would like to create a viewer to a Simulink connection from block A to block B. I know how to do it manually (right click on connection > Create & Connect Viewer > Simulink > Scope) but I would like to do it programmatically through command lines, something like get_param(A, ...). Thanks.
  2 Comments
Joachim Wagner
Joachim Wagner on 9 Sep 2019
I have the same problem. Is there no answer to this question? Would be very helpful!
Fabien Fellay
Fabien Fellay on 30 Jun 2020
I found this workaround. But as it is partly undocumented (and not so stable), keep a backup of your model before giving it a try.
Create a regular scope 'myScope' and insert it in your model.
mdl = 'Simu_Main';
add_block('simulink/Sinks/Scope',[mdl,'/myScope']);
Change it into a scope viewer (note that the Simulink UI will not take the change into account immediatly as the scope will still be visible):
set_param([mdl,'/myScope'],'IOType','viewer');
Then, you have to 'connect' the scope viewer to some signals, provided you know the signals names. For that, use:
io_structure = get_param([mdl,'/myScope'],'IOSignalStrings')
But then, you have to edit the io_structure to attach some signals to the scope (many possibilities seems available: several signals in one single axes system, or several axes systems, etc.). This seems to be undocumented. Maybe create a scope viewer with the regular interface, as you wish, and then look at the created 'IOSignalStrings' parameter to underestand the principle.
When you are done with your io_structure, set it:
set_param([mdl,'/myScope'],'IOSignalStrings',io_structure)
Finally, configure your scope (title, axes labels, etc.) with:
scope_viewer_config = get_param([mdl,'/myScope'],'ScopeConfiguration')
and edit programmatically scope_viewer_config according to the existing documentation. Finally, save your model, close it and reopen it (this part seems unstable, closing and reopening Matlab generally solve the issue). Now, you created your scope viewer programmatically: if you open the model, the regular scope should now be graphically turned into a working scope viewer.
I confirm that it would be appreciated if Matlab could provide an official clean and documented way of creating and managing scope viewer programmatically (including 'commenting them out', instead of deleting them).

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!