<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Organizing Mask Callbacks</title>
	<link>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/</link>
	<description>This blog is about Simulink.</description>
	<pubDate>Sun, 22 Nov 2009 23:35:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<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>http://blogs.mathworks.com/seth/2008/08/28/organizing-mask-callbacks/#comment-633</guid>
		<description>I'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'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>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 - 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>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 "Initialization-Code" of the Mask-Editor? 

At first I've tried to use the paremeter 'CompiledPortWidth' of the input port with these 4 commands:

modelname([],[],[],'compile');
q=get_param(gcb,'PortHandles');
dim = get_param(q.Inport(1),'CompiledPortWidth')
modelname([],[],[],'term');

It doesn't work in the 'Initialization-Code' 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 'Probe'. This block detects the width/dimension and generates a signal with that value. But I don't know how to use the value of an input-signal in the 'Initialization-Code' 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>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 ("Main" and "Signal Attributes"). The dialog window also uses multi-columns. Further, there is "Data Type Assistant" feature which can be shown/hidden with a button, iconed '&#60;&#62;', 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 (&#8221;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>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're discussing it, does TMW publish a "best practices" document for developing Simulink blocks?  That would be helpful.  (Your articles on masking contain content that I'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>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'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 - 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>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 "enumeration" of parameter indices. Now my callback switchyard calls get_param(blk, 'MaskNames') and passes that result to the individual handlers.  Using the global enumerated indices, I don'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've found that I have to try evaluating the get_param() results in first the model workspace, and then the caller (i.e. MATLAB'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>
