Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Simulink Mask Parameter Range Checking
Date: Wed, 21 Oct 2009 18:45:09 +0000 (UTC)
Organization: Crane Aerospace
Lines: 21
Message-ID: <hbnkrl$31a$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1256150709 3114 172.30.248.38 (21 Oct 2009 18:45:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 21 Oct 2009 18:45:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1091246
Xref: news.mathworks.com comp.soft-sys.matlab:579084


I am new to dealing with callback functions, and had a question about range checking, and throwing an error.

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?

function range_check(varName, errMsgName)      
    %check that varName is not empty (meaning a string was entered),
    %is an integer, and is positive
    if (isempty(varName) || ...
        rem(varName, 1) ~= 0 || ...
       (rem(varName, 1) == 0 && varName < 1))
        errordlg(['Number of ' errMsgName ' must be a ' ...
                 'positive integer.'], ...
                 'Error: Function Block Parameters');
    end %if
end %function

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?

Thanks,

Richard