4.5

4.5 | 2 ratings Rate this file 3 Downloads (last 30 days) File Size: 10.59 KB File ID: #24745
image thumbnail

Dealing with array of buses in Simulink®

by Vijay Swaminathan

 

15 Jul 2009 (Updated 10 Aug 2009)

This demo shows a self modifying masked subsystem to split out the correct subbus from the superbus.

| Watch this File

File Information
Description

Here is the situation. Suppose you have a model that can analyze the properties of a meteor to track its trajectory. You want to use it in a larger model which tracks many such meteors at the same time. You now need a block that can accept a superbus called Mainbus (that contains a lot of subbuses called meteorbus) and split out the relevant subbus (metoerbus).

This block should be able to handles any changes in MainBus and meteorbus automatically on model update (no manual intervention).

Solution: Look at the example “ArrayofBus_example.mdl”. I created a masked subsystem “Meteor Selector” which automatically looks at the Bus Objects (MainBus and meteorbus), figures out how many meteors are in the “MainBus” and the structure of the “misbus” and pulls out the correct meteor.

 I simply used a Bus Selector which splits out ALL the meteors and then use a Multiport Switch to pass through the correct meteor(based on input frm the mask) to the outport. The tricky part is to get this to work if the number of meteors in MainBus changes. I got this to happen by writing a script that figures out what needs to be done (at the time of model update) and put that in Mask Initialization callback. Essentially you have to set the correct number of ports for the Bus Selector and the Multiport Switch, delete the existing signal lines and add the required lines.

Instructions:

Open the model “ArrayofBus_example.mdl” and follow the instructions in the annotation.

Required Products Simulink
MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
29 Sep 2009 matlab kid

Good one..Very usefull .
Do you have any script to change the signal names from commandline...?

01 Oct 2009 Vijay Swaminathan

Hi,

You can indeed set signal properties like”Name” from the command, but the trick is you have to get the handle first. The easiest way to get the handle is through the block whose *outport* is connected to the signal. Do not use the inport of the block that the signal feeds to, as the properties will be read-only there.

Here is a simple example:

1. Open up a demo model called vdp.mdl
2. Let’s say I want to set the name of the signal coming out of the gain block “Mu” to be “blah”.

>> myhandles = get_param('vdp/Mu','PortHandles')

Inport: 2.5270e+003
     Outport: 2.5280e+003
      Enable: []
     Trigger: []
       State: []
       LConn: []
       RConn: []
    Ifaction: []

>> set_param( myhandles.Outport,'Name','blah')

You should now see in the model that the signal has been named.

You can use this technique in conjunction with the find_system command to do very powerful things.

Regards,
Vijay

Please login to add a comment or rating.
Updates
10 Aug 2009

Minor changes in description and comments

10 Aug 2009

Title update

Tag Activity for this File
Tag Applied By Date/Time
self modifying masks Vijay Swaminathan 10 Aug 2009 11:30:25
array of buses Vijay Swaminathan 10 Aug 2009 11:30:25
building models from the command line Vijay Swaminathan 10 Aug 2009 11:30:25
self_rating Matt Fig 02 Oct 2009 01:04:45

Contact us at files@mathworks.com