Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Control SimEvents Models via m-file

Subject: Control SimEvents Models via m-file

From: Tiger

Date: 17 Mar, 2013 23:12:05

Message: 1 of 7

Hi folks,

Can I, for instance, change a block in a SimEvents model from one type to another from an m-file. In other words, can I write a script that tells the SimEvents model, before launching the simulation, to change a FIFO Queue block into a Prioriy Queue providing the Attribute_source for the priority.

Thanks.

Subject: Control SimEvents Models via m-file

From: Phil Goddard

Date: 18 Mar, 2013 02:17:23

Message: 2 of 7

Yes, see the doc for replace_block
http://www.mathworks.com/help/simulink/slref/replace_block.html

You most likely will need to use set_param too.

Phil.

Subject: Control SimEvents Models via m-file

From: Tiger

Date: 19 Mar, 2013 23:24:06

Message: 3 of 7

Thanks Phil.

When I enter a SimEvents block in the 'new_blk' argument of 'replace_block' I get the following error:
??? Error using ==> replace_block at 107
Invalid NewBlock (...) passed to REPLACE_BLOCK
Try built-in/<BLOCKTYPE> or a valid block name.

However, it works well with SimEvents blocks in the 'old_blk' argumet, not sure what's the explaination for that? For instance, the following worked well:
>> replace_block('sys', 'FIFO Queue', 'Constant', 'noprompt')
The following doesn't work:
>> replace_block('sys', 'Constant', 'FIFO Queue', 'noprompt')

What I want to do is replace a FIFO Queue with a Priority Queue, then use, as you suggested earlier, 'set_param' to modify the AttributeName for the priority used. That's all.

I've tried using 'built-in/' as the error message suggests, but no results. I've tried putting the pathname, nothing. I even tried putting the path name of the SimEvents toolbox in my Matlab directory (C:ProgramFiles..), and no results.

Why SimEvents blocks work well as 'old_blks' but not 'new_blks'?

Subject: Control SimEvents Models via m-file

From: Teresa Hubscher-Younger

Date: 25 Mar, 2013 10:08:09

Message: 4 of 7

Hi Tiger,

This is mysterious. You do need a pathname, which you can get by clicking on a block and typing in gcb. But if I read your message right, you've done that.

These were the steps specified by a developer to try out things to make sure they are working correctly.

>> open_system sedemo_mm1 % as a test model
>> open_system simeventslib % open simevents library
>> replace_block('sedemo_mm1', 'Name', 'FIFO Queue', 'simeventslib/Queues/Priority Queue')

If you know the block types, then the syntax is simpler:

>> replace_block('sedemo_mm1', 'FIFOQueue', 'PriorityQueue')

To find out the block type of a block you can do:

>> get_param(gcb, 'BlockType')

If you are continuing to have trouble with this, then please email me back and write a Support Request. (If you are using 12b, there is a pull-down choice to do this from MATLAB.) We need to get to the bottom of what is going on with this.

Thanks,
Teresa

"Tiger" wrote in message <kias2m$36u$1@newscl01ah.mathworks.com>...
> Thanks Phil.
>
> When I enter a SimEvents block in the 'new_blk' argument of 'replace_block' I get the following error:
> ??? Error using ==> replace_block at 107
> Invalid NewBlock (...) passed to REPLACE_BLOCK
> Try built-in/<BLOCKTYPE> or a valid block name.
>
> However, it works well with SimEvents blocks in the 'old_blk' argumet, not sure what's the explaination for that? For instance, the following worked well:
> >> replace_block('sys', 'FIFO Queue', 'Constant', 'noprompt')
> The following doesn't work:
> >> replace_block('sys', 'Constant', 'FIFO Queue', 'noprompt')
>
> What I want to do is replace a FIFO Queue with a Priority Queue, then use, as you suggested earlier, 'set_param' to modify the AttributeName for the priority used. That's all.
>
> I've tried using 'built-in/' as the error message suggests, but no results. I've tried putting the pathname, nothing. I even tried putting the path name of the SimEvents toolbox in my Matlab directory (C:ProgramFiles..), and no results.
>
> Why SimEvents blocks work well as 'old_blks' but not 'new_blks'?

Subject: Control SimEvents Models via m-file

From: Teresa Hubscher-Younger

Date: 26 Mar, 2013 10:50:07

Message: 5 of 7

Hi Tiger,

I thought of another thing that could be causing confusion. When you swap out a block, it doesn't change the name. This confused me at first. In other words, if you have a FIFO Queue block and switch it with a Priority Queue block, the block will still be named "FIFO Queue". If you double click on the block, though, you can see that the name is just a name, and the dialog is for the Priority Queue. This is because when you replace a block, it's not clear you actually want to change the name. You might have renamed the block to be something special. You will need to explicitly change the name with a set_param if you want to change the name, as well as change the block.

-Teresa

"Teresa Hubscher-Younger" <teresa.hubscher-younger@mathworks.com> wrote in message <kip7m9$kcc$1@newscl01ah.mathworks.com>...
> Hi Tiger,
>
> This is mysterious. You do need a pathname, which you can get by clicking on a block and typing in gcb. But if I read your message right, you've done that.
>
> These were the steps specified by a developer to try out things to make sure they are working correctly.
>
> >> open_system sedemo_mm1 % as a test model
> >> open_system simeventslib % open simevents library
> >> replace_block('sedemo_mm1', 'Name', 'FIFO Queue', 'simeventslib/Queues/Priority Queue')
>
> If you know the block types, then the syntax is simpler:
>
> >> replace_block('sedemo_mm1', 'FIFOQueue', 'PriorityQueue')
>
> To find out the block type of a block you can do:
>
> >> get_param(gcb, 'BlockType')
>
> If you are continuing to have trouble with this, then please email me back and write a Support Request. (If you are using 12b, there is a pull-down choice to do this from MATLAB.) We need to get to the bottom of what is going on with this.
>
> Thanks,
> Teresa
>
> "Tiger" wrote in message <kias2m$36u$1@newscl01ah.mathworks.com>...
> > Thanks Phil.
> >
> > When I enter a SimEvents block in the 'new_blk' argument of 'replace_block' I get the following error:
> > ??? Error using ==> replace_block at 107
> > Invalid NewBlock (...) passed to REPLACE_BLOCK
> > Try built-in/<BLOCKTYPE> or a valid block name.
> >
> > However, it works well with SimEvents blocks in the 'old_blk' argumet, not sure what's the explaination for that? For instance, the following worked well:
> > >> replace_block('sys', 'FIFO Queue', 'Constant', 'noprompt')
> > The following doesn't work:
> > >> replace_block('sys', 'Constant', 'FIFO Queue', 'noprompt')
> >
> > What I want to do is replace a FIFO Queue with a Priority Queue, then use, as you suggested earlier, 'set_param' to modify the AttributeName for the priority used. That's all.
> >
> > I've tried using 'built-in/' as the error message suggests, but no results. I've tried putting the pathname, nothing. I even tried putting the path name of the SimEvents toolbox in my Matlab directory (C:ProgramFiles..), and no results.
> >
> > Why SimEvents blocks work well as 'old_blks' but not 'new_blks'?

Subject: Control SimEvents Models via m-file

From: Tiger

Date: 27 Mar, 2013 05:04:06

Message: 6 of 7

Hi Teresa,

Thanks for your replies. I tried your developer steps:
>> open_system sedemo_mm1 % as a test model
>> imeventslib % open simevents library
>> replace_block('sedemo_mm1', 'Name', 'FIFO Queue', 'simeventslib/Queues/Priority Queue')

It failed, again, exactly the same way it did with my SimEvents model. I've tried 'simeventslib/Queues/Priority Queue' on my SimEvents mode, and the same error keeps on appearing:
"??? Error using ==> replace_block at 107
Invalid NewBlock (simeventslib/Queues/Priority Queue) passed to REPLACE_BLOCK
Try built-in/<BLOCKTYPE> or a valid block name."

The pathname to the subsystem of my SimEvents model where the FIFO Queue block resides is correct as I've tested replacing the FIFO Queue block with a Constant block and it worked well, but when I tried replacing the Constant block back to a FIFO Queue block, it complained as above.

I've tried all different possible syntaxes like:
'PriorityQueue'
'Priority Queue'
'simeventslib/Queues/Priority Queue'
'simeventslib/Queues/PriorityQueue'
'simeventslib/Priority Queue'
'simeventslib/PriorityQueue'
'built-in/Priority Queue'
'built-in/PriorityQueue'

I'm puzzled.

Subject: Control SimEvents Models via m-file

From: Teresa Hubscher-Younger

Date: 27 Mar, 2013 10:32:07

Message: 7 of 7

Hi Tiger,

OK, I am puzzled too. You should not be getting the error you are getting. I would suggest talking to Technical Support at this point, because they are better at getting at the root of the problem and if it is a bug, getting it resolved. You can go to this page and create a technical service request:
http://www.mathworks.com/support/service_requests/contact_support.do

Sorry, I cannot be more helpful at this point,
Teresa

"Tiger" wrote in message <kituk6$q3q$1@newscl01ah.mathworks.com>...
> Hi Teresa,
>
> Thanks for your replies. I tried your developer steps:
> >> open_system sedemo_mm1 % as a test model
> >> imeventslib % open simevents library
> >> replace_block('sedemo_mm1', 'Name', 'FIFO Queue', 'simeventslib/Queues/Priority Queue')
>
> It failed, again, exactly the same way it did with my SimEvents model. I've tried 'simeventslib/Queues/Priority Queue' on my SimEvents mode, and the same error keeps on appearing:
> "??? Error using ==> replace_block at 107
> Invalid NewBlock (simeventslib/Queues/Priority Queue) passed to REPLACE_BLOCK
> Try built-in/<BLOCKTYPE> or a valid block name."
>
> The pathname to the subsystem of my SimEvents model where the FIFO Queue block resides is correct as I've tested replacing the FIFO Queue block with a Constant block and it worked well, but when I tried replacing the Constant block back to a FIFO Queue block, it complained as above.
>
> I've tried all different possible syntaxes like:
> 'PriorityQueue'
> 'Priority Queue'
> 'simeventslib/Queues/Priority Queue'
> 'simeventslib/Queues/PriorityQueue'
> 'simeventslib/Priority Queue'
> 'simeventslib/PriorityQueue'
> 'built-in/Priority Queue'
> 'built-in/PriorityQueue'
>
> I'm puzzled.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us