<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263769</link>
    <title>MATLAB Central Newsreader - Simulink Mask Parameter Range Checking</title>
    <description>Feed for thread: Simulink Mask Parameter Range Checking</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 21 Oct 2009 18:45:09 -0400</pubDate>
      <title>Simulink Mask Parameter Range Checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263769#688776</link>
      <author>Richard </author>
      <description>I am new to dealing with callback functions, and had a question about range checking, and throwing an error.&lt;br&gt;
&lt;br&gt;
I have a masked subsystem with two parameters that I would like to range check.  I want to ensure that the value entered is a positive integer.  I currently have the following initialization command callback function that runs whenever the block is initialized.  Both parameters have the Evaluate box checked in the Dialog parameters field of the Mask Editor, which as far as I can tell returns null if a string that is not a valid variable name is entered instead of a number or variable.  Is this true?&lt;br&gt;
&lt;br&gt;
function range_check(varName, errMsgName)      &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%check that varName is not empty (meaning a string was entered),&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%is an integer, and is positive&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (isempty(varName) || ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rem(varName, 1) ~= 0 || ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(rem(varName, 1) == 0 &amp;&amp; varName &amp;lt; 1))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;errordlg(['Number of ' errMsgName ' must be a ' ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'positive integer.'], ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'Error: Function Block Parameters');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end %if&lt;br&gt;
end %function&lt;br&gt;
&lt;br&gt;
This gives me an error if I click OK or APPLY (as desired), but the value still accepted, and if I click OK after the error has displayed, the Function Block Parameter box disappears, and the invalid parameter value is stored.  What is the best way to display an error message and not store the invalid value?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
Richard</description>
    </item>
    <item>
      <pubDate>Wed, 21 Oct 2009 19:55:48 -0400</pubDate>
      <title>Re: Simulink Mask Parameter Range Checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263769#688784</link>
      <author>Praetorian</author>
      <description>On Oct 21, 12:45&#160;pm, &quot;Richard &quot; &amp;lt;richard.schwa...@craneaerospace.com&amp;gt;&lt;br&gt;
wrote:&lt;br&gt;
&amp;gt; I am new to dealing with callback functions, and had a question about range checking, and throwing an error.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have a masked subsystem with two parameters that I would like to range check. &#160;I want to ensure that the value entered is a positive integer. &#160;I currently have the following initialization command callback function that runs whenever the block is initialized. &#160;Both parameters have the Evaluate box checked in the Dialog parameters field of the Mask Editor, which as far as I can tell returns null if a string that is not a valid variable name is entered instead of a number or variable. &#160;Is this true?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; function range_check(varName, errMsgName) &#160; &#160; &#160;&lt;br&gt;
&amp;gt; &#160; &#160; %check that varName is not empty (meaning a string was entered),&lt;br&gt;
&amp;gt; &#160; &#160; %is an integer, and is positive&lt;br&gt;
&amp;gt; &#160; &#160; if (isempty(varName) || ...&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; rem(varName, 1) ~= 0 || ...&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160;(rem(varName, 1) == 0 &amp;&amp; varName &amp;lt; 1))&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; errordlg(['Number of ' errMsgName ' must be a ' ...&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;'positive integer.'], ...&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;'Error: Function Block Parameters');&lt;br&gt;
&amp;gt; &#160; &#160; end %if&lt;br&gt;
&amp;gt; end %function&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; This gives me an error if I click OK or APPLY (as desired), but the value still accepted, and if I click OK after the error has displayed, the Function Block Parameter box disappears, and the invalid parameter value is stored. &#160;What is the best way to display an error message and not store the invalid value?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Richard&lt;br&gt;
&lt;br&gt;
The way I've dealt with this in the past is to have a hidden edit box&lt;br&gt;
which holds the last valid entry. If the current entry is invalid then&lt;br&gt;
you load the contents of this hidden edit box into the visible one and&lt;br&gt;
display the error, all within your callback function. Maybe&lt;br&gt;
(hopefully) someone has a better solution.&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
Ashish.</description>
    </item>
    <item>
      <pubDate>Wed, 21 Oct 2009 20:49:06 -0400</pubDate>
      <title>Re: Simulink Mask Parameter Range Checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263769#688796</link>
      <author>Richard </author>
      <description>Praetorian &amp;lt;ashish.sadanandan@gmail.com&amp;gt; wrote in message &amp;lt;ae9f390d-f976-4af2-b8f8-64ea7d7b485b@d34g2000vbm.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Oct 21, 12:45?pm, &quot;Richard &quot; &amp;lt;richard.schwa...@craneaerospace.com&amp;gt;&lt;br&gt;
&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; I am new to dealing with callback functions, and had a question about range checking, and throwing an error.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have a masked subsystem with two parameters that I would like to range check. ?I want to ensure that the value entered is a positive integer. ?I currently have the following initialization command callback function that runs whenever the block is initialized. ?Both parameters have the Evaluate box checked in the Dialog parameters field of the Mask Editor, which as far as I can tell returns null if a string that is not a valid variable name is entered instead of a number or variable. ?Is this true?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; function range_check(varName, errMsgName) ? ? ?&lt;br&gt;
&amp;gt; &amp;gt; ? ? %check that varName is not empty (meaning a string was entered),&lt;br&gt;
&amp;gt; &amp;gt; ? ? %is an integer, and is positive&lt;br&gt;
&amp;gt; &amp;gt; ? ? if (isempty(varName) || ...&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? rem(varName, 1) ~= 0 || ...&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ?(rem(varName, 1) == 0 &amp;&amp; varName &amp;lt; 1))&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? errordlg(['Number of ' errMsgName ' must be a ' ...&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? ? ? ? ? ?'positive integer.'], ...&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? ? ? ? ? ?'Error: Function Block Parameters');&lt;br&gt;
&amp;gt; &amp;gt; ? ? end %if&lt;br&gt;
&amp;gt; &amp;gt; end %function&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; This gives me an error if I click OK or APPLY (as desired), but the value still accepted, and if I click OK after the error has displayed, the Function Block Parameter box disappears, and the invalid parameter value is stored. ?What is the best way to display an error message and not store the invalid value?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Richard&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The way I've dealt with this in the past is to have a hidden edit box&lt;br&gt;
&amp;gt; which holds the last valid entry. If the current entry is invalid then&lt;br&gt;
&amp;gt; you load the contents of this hidden edit box into the visible one and&lt;br&gt;
&amp;gt; display the error, all within your callback function. Maybe&lt;br&gt;
&amp;gt; (hopefully) someone has a better solution.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; HTH,&lt;br&gt;
&amp;gt; Ashish.&lt;br&gt;
&lt;br&gt;
This could work, however I was thinking more along the lines of how Simulink does it with their blocks.  For instance if you have a Logical Operator block and put -2 as the number of input ports or an AND operator, the field turns tan showing that the value has been changed, and I think this means that the Initialization callback has to be executed.  If you click Apply, an error is generated, the field turns white, but then when you click OK on the error message, the incorrect -2 stays in the field, but the field is tan again, and Apply is still active, so if you were to click OK or Apply, it would re-generate the error.  Is there a parameter that i can use with set_param to do something like field_changed = true and thus re-run my callback range check function if OK or Apply is clicked again?</description>
    </item>
  </channel>
</rss>

