<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Organizing Mask Callbacks</title>
	<atom:link href="http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/</link>
	<description>This blog is about Simulink.</description>
	<lastBuildDate>Sat, 11 Feb 2012 11:34:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Seth</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-1024</link>
		<dc:creator>Seth</dc:creator>
		<pubDate>Tue, 23 Mar 2010 20:22:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-1024</guid>
		<description>@Jack - The gain value from your mask will not be in the base workspace.  The preferred method to access these variables from the MaskInitialization code is to pass them into the function or just use the value.  It is assigned in the mask workspace before the MaskInitialization code runs, so it should be available.

There is an example of this in my post on &lt;a href=&quot;http://blogs.mathworks.com/seth/2008/08/21/mask-initialization-and-self-modifying-blocks/&quot; rel=&quot;nofollow&quot;&gt;Mask Initialization&lt;/a&gt;.

I recommend against using evalin inside MaskInitialization because it is hard to code for all the different cases handled by hierarchical resolution.</description>
		<content:encoded><![CDATA[<p>@Jack &#8211; The gain value from your mask will not be in the base workspace.  The preferred method to access these variables from the MaskInitialization code is to pass them into the function or just use the value.  It is assigned in the mask workspace before the MaskInitialization code runs, so it should be available.</p>
<p>There is an example of this in my post on <a href="http://blogs.mathworks.com/seth/2008/08/21/mask-initialization-and-self-modifying-blocks/" rel="nofollow">Mask Initialization</a>.</p>
<p>I recommend against using evalin inside MaskInitialization because it is hard to code for all the different cases handled by hierarchical resolution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-1018</link>
		<dc:creator>Jack</dc:creator>
		<pubDate>Mon, 22 Mar 2010 12:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-1018</guid>
		<description>I organize my mask callbacks like you but when the masked blocks are used in a mask susbsystem, I get an exception when I try to evaluate the subsystem parameter from the masked block. For example my masked block is &#039;Timestwo&#039; with parameter &#039;gain&#039;. I put Timestwo in a masked subsytem named &#039;Top&#039; with parameter &#039;topgain&#039;. I initialize the parameter &#039;gain&#039; of Top/Timestwo at &#039;topgain&#039;. When I use evalin(&#039;base&#039;,get_param(&#039;Top/Timestwo&#039;, &#039;gain&#039;)), I get an exception which states that the parameter &#039;topgain&#039; is undentified. Is there a way to access to parent parameter from the child ?

Thanks for your help</description>
		<content:encoded><![CDATA[<p>I organize my mask callbacks like you but when the masked blocks are used in a mask susbsystem, I get an exception when I try to evaluate the subsystem parameter from the masked block. For example my masked block is &#8216;Timestwo&#8217; with parameter &#8216;gain&#8217;. I put Timestwo in a masked subsytem named &#8216;Top&#8217; with parameter &#8216;topgain&#8217;. I initialize the parameter &#8216;gain&#8217; of Top/Timestwo at &#8216;topgain&#8217;. When I use evalin(&#8216;base&#8217;,get_param(&#8216;Top/Timestwo&#8217;, &#8216;gain&#8217;)), I get an exception which states that the parameter &#8216;topgain&#8217; is undentified. Is there a way to access to parent parameter from the child ?</p>
<p>Thanks for your help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Albert Kröber</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-633</link>
		<dc:creator>Albert Kröber</dc:creator>
		<pubDate>Mon, 08 Dec 2008 12:12:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-633</guid>
		<description>I&#039;ve asked the Mathworks support. And they said that it is not possible to detect the signal width in the inizialization code of a mask. Also the Probe-block can&#039;t solve the problem. 

At the moment the user has to write the signal width by himself in the mask of the block. 

Anyway, thank you for your help</description>
		<content:encoded><![CDATA[<p>I&#8217;ve asked the Mathworks support. And they said that it is not possible to detect the signal width in the inizialization code of a mask. Also the Probe-block can&#8217;t solve the problem. </p>
<p>At the moment the user has to write the signal width by himself in the mask of the block. </p>
<p>Anyway, thank you for your help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seth</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-617</link>
		<dc:creator>Seth</dc:creator>
		<pubDate>Tue, 25 Nov 2008 14:02:51 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-617</guid>
		<description>@Albert Kröber - The model function should not be called from the initialization code of a Mask.  Mask initialization is called during initialization of the model.  This means, at the start of the simulation your block would start to initialize itself, again during the process of init.  THEN, the same block would tell the model to terminate.  I believe we prevent this from working in the initialization code to prevent a infinite loop.

You can use the get_param commands to gather the CompilePortWidth, but there will be a result of 0 when the model is not compiled.  You can check for this 0 in a conditional command and only apply an action when the value is non-zero and your data is valid, otherwise, do nothing.

&lt;em&gt;How are you using this information?&lt;/em&gt;  The Probe block can return the signal width as a signal line which is used in a downstream calculation.  This is often preferred over depending on initialization code to gather this information.</description>
		<content:encoded><![CDATA[<p>@Albert Kröber &#8211; The model function should not be called from the initialization code of a Mask.  Mask initialization is called during initialization of the model.  This means, at the start of the simulation your block would start to initialize itself, again during the process of init.  THEN, the same block would tell the model to terminate.  I believe we prevent this from working in the initialization code to prevent a infinite loop.</p>
<p>You can use the get_param commands to gather the CompilePortWidth, but there will be a result of 0 when the model is not compiled.  You can check for this 0 in a conditional command and only apply an action when the value is non-zero and your data is valid, otherwise, do nothing.</p>
<p><em>How are you using this information?</em>  The Probe block can return the signal width as a signal line which is used in a downstream calculation.  This is often preferred over depending on initialization code to gather this information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Albert Kröber</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-612</link>
		<dc:creator>Albert Kröber</dc:creator>
		<pubDate>Thu, 20 Nov 2008 15:09:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-612</guid>
		<description>Hi Seth,

Is it possible to detect the width or dimension of an input signal of a masked block in the &quot;Initialization-Code&quot; of the Mask-Editor? 

At first I&#039;ve tried to use the paremeter &#039;CompiledPortWidth&#039; of the input port with these 4 commands:

modelname([],[],[],&#039;compile&#039;);
q=get_param(gcb,&#039;PortHandles&#039;);
dim = get_param(q.Inport(1),&#039;CompiledPortWidth&#039;)
modelname([],[],[],&#039;term&#039;);

It doesn&#039;t work in the &#039;Initialization-Code&#039; but in the MATLAB prompt. Do you know where I can add code that is executed while the model is compiled. 

My second idea was the block &#039;Probe&#039;. This block detects the width/dimension and generates a signal with that value. But I don&#039;t know how to use the value of an input-signal in the &#039;Initialization-Code&#039; of the Mask-Editor.

Have you any idea?

Thanks for your help and all the tutorials.

Albert</description>
		<content:encoded><![CDATA[<p>Hi Seth,</p>
<p>Is it possible to detect the width or dimension of an input signal of a masked block in the &#8220;Initialization-Code&#8221; of the Mask-Editor? </p>
<p>At first I&#8217;ve tried to use the paremeter &#8216;CompiledPortWidth&#8217; of the input port with these 4 commands:</p>
<p>modelname([],[],[],&#8217;compile&#8217;);<br />
q=get_param(gcb,&#8217;PortHandles&#8217;);<br />
dim = get_param(q.Inport(1),&#8217;CompiledPortWidth&#8217;)<br />
modelname([],[],[],&#8217;term&#8217;);</p>
<p>It doesn&#8217;t work in the &#8216;Initialization-Code&#8217; but in the MATLAB prompt. Do you know where I can add code that is executed while the model is compiled. </p>
<p>My second idea was the block &#8216;Probe&#8217;. This block detects the width/dimension and generates a signal with that value. But I don&#8217;t know how to use the value of an input-signal in the &#8216;Initialization-Code&#8217; of the Mask-Editor.</p>
<p>Have you any idea?</p>
<p>Thanks for your help and all the tutorials.</p>
<p>Albert</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wei</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-545</link>
		<dc:creator>wei</dc:creator>
		<pubDate>Tue, 09 Sep 2008 12:09:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-545</guid>
		<description>Hi Seth,
For some build-in blocks (for example, the constant block), there are multiple tabs (&quot;Main&quot; and &quot;Signal Attributes&quot;). The dialog window also uses multi-columns. Further, there is &quot;Data Type Assistant&quot; feature which can be shown/hidden with a button, iconed &#039;&lt;&gt;&#039;, click.

How could Simulink modelers add these capabilities for their custom blocks without invoking handle graphics?</description>
		<content:encoded><![CDATA[<p>Hi Seth,<br />
For some build-in blocks (for example, the constant block), there are multiple tabs (&#8220;Main&#8221; and &#8220;Signal Attributes&#8221;). The dialog window also uses multi-columns. Further, there is &#8220;Data Type Assistant&#8221; feature which can be shown/hidden with a button, iconed &#8216;&lt;&gt;&#8217;, click.</p>
<p>How could Simulink modelers add these capabilities for their custom blocks without invoking handle graphics?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Reilly</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-544</link>
		<dc:creator>John Reilly</dc:creator>
		<pubDate>Tue, 09 Sep 2008 11:37:51 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-544</guid>
		<description>Seth:  Thanks for your reply.  I have constant block values that depend upon parameter values.  In order to provide user notification as early as possible, I have my mask callback for parameter A calculate the constant C whenever A changes.  That way I can generate an error as soon as possible.  From a usability perspective, I feel this is the best experience.  But it sounds like I should wait until initialization?

While we&#039;re discussing it, does TMW publish a &quot;best practices&quot; document for developing Simulink blocks?  That would be helpful.  (Your articles on masking contain content that I&#039;d like to see in such a tome.)

Thanks again.
reilly.</description>
		<content:encoded><![CDATA[<p>Seth:  Thanks for your reply.  I have constant block values that depend upon parameter values.  In order to provide user notification as early as possible, I have my mask callback for parameter A calculate the constant C whenever A changes.  That way I can generate an error as soon as possible.  From a usability perspective, I feel this is the best experience.  But it sounds like I should wait until initialization?</p>
<p>While we&#8217;re discussing it, does TMW publish a &#8220;best practices&#8221; document for developing Simulink blocks?  That would be helpful.  (Your articles on masking contain content that I&#8217;d like to see in such a tome.)</p>
<p>Thanks again.<br />
reilly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seth</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-532</link>
		<dc:creator>Seth</dc:creator>
		<pubDate>Fri, 05 Sep 2008 03:48:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-532</guid>
		<description>@ John Reily - The string entered into your mask will be evaluated in the parent workspace, (it could come from a system above the current one), or it may trace all the way back to the base workspace.

The Dialog Callback is tricky because you can&#039;t always guarantee that the value is known.  For example, when I set a gain value of A, I often later add that to the model workspace, or base workspace.  The tricky problem you face is trying to anticipate where the variable is coming from, and as you note, it could be in the model workspace, the MATLAB base workspace, or some parent system workspace that passed down through hierarchical resolution.

An alternative design is to use Mask Initialization to check the value.  At that point, the value is known and available to your code without calling get_param.

Can you give more details about what you are trying to do in yor mask callback?</description>
		<content:encoded><![CDATA[<p>@ John Reily &#8211; The string entered into your mask will be evaluated in the parent workspace, (it could come from a system above the current one), or it may trace all the way back to the base workspace.</p>
<p>The Dialog Callback is tricky because you can&#8217;t always guarantee that the value is known.  For example, when I set a gain value of A, I often later add that to the model workspace, or base workspace.  The tricky problem you face is trying to anticipate where the variable is coming from, and as you note, it could be in the model workspace, the MATLAB base workspace, or some parent system workspace that passed down through hierarchical resolution.</p>
<p>An alternative design is to use Mask Initialization to check the value.  At that point, the value is known and available to your code without calling get_param.</p>
<p>Can you give more details about what you are trying to do in yor mask callback?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Reilly</title>
		<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-519</link>
		<dc:creator>John Reilly</dc:creator>
		<pubDate>Fri, 29 Aug 2008 14:18:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-519</guid>
		<description>Seth:
Thanks for a great series. As I am in the process of building a set of Simulink blocks, these were both timely and helpful.

I took your advice, and the advice of a commenter to create an &quot;enumeration&quot; of parameter indices. Now my callback switchyard calls get_param(blk, &#039;MaskNames&#039;) and passes that result to the individual handlers.  Using the global enumerated indices, I don&#039;t change any code if I rename parameters.  I just have to keep the enumerations up to date.

One question.  If my parameter is set to a variable, get_param() in my callbacks returns that variable string.  I&#039;ve found that I have to try evaluating the get_param() results in first the model workspace, and then the caller (i.e. MATLAB&#039;s) workspace if I need the actual numeric value.  Is this indeed the case?  Is their an easier way?

Thanks again.
reilly.</description>
		<content:encoded><![CDATA[<p>Seth:<br />
Thanks for a great series. As I am in the process of building a set of Simulink blocks, these were both timely and helpful.</p>
<p>I took your advice, and the advice of a commenter to create an &#8220;enumeration&#8221; of parameter indices. Now my callback switchyard calls get_param(blk, &#8216;MaskNames&#8217;) and passes that result to the individual handlers.  Using the global enumerated indices, I don&#8217;t change any code if I rename parameters.  I just have to keep the enumerations up to date.</p>
<p>One question.  If my parameter is set to a variable, get_param() in my callbacks returns that variable string.  I&#8217;ve found that I have to try evaluating the get_param() results in first the model workspace, and then the caller (i.e. MATLAB&#8217;s) workspace if I need the actual numeric value.  Is this indeed the case?  Is their an easier way?</p>
<p>Thanks again.<br />
reilly.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

