Main Content

非アクティブなプロパティの非表示

アクティブな System object™ プロパティのみを表示するには、isInactivePropertyImplメソッドを使用します。このメソッドは、プロパティが非アクティブかどうかを指定します。"非アクティブなプロパティ"は、他のプロパティの値があるために、System object に影響しないプロパティです。isInactivePropertyメソッドをプロパティに渡し、このメソッドがtrueを返すと、そのプロパティは非アクティブであり、関数dispの呼び出し時に表示されません。

非アクティブなプロパティの指定

この例では、isInactivePropertyメソッドを使用して、依存プロパティの値を確認します。この System object のUseRandomInitialValueが true に設定されている場合、InitialValueプロパティは関係ありません。このisInactivePropertyメソッドはその状況を確認し、UseRandomInitialValuetrueの場合は、trueを返して、非アクティブなInitialValueプロパティを非表示にします。

methods (Access = protected)functionflag = isInactivePropertyImpl(obj,propertyName)ifstrcmp(propertyName,'InitialValue') flag = obj.UseRandomInitialValue;else国旗= false;endendend

非アクティブなプロパティ メソッドを使用した完全なクラス定義ファイル

classdefCounter < matlab.System% Counter Increment a counter% These properties are nontunable. They cannot be changed% after the setup method has been called or when the% object is running.properties(Nontunable)% Allow the user to set the initial valueUseRandomInitialValue = true InitialValue = 0end% The private count variable, which is tunable by defaultproperties(访问= private) pCountendmethods(Access = protected)% Increment the counter and return its value% as an outputfunctionc = stepImpl(obj) obj.pCount = obj.pCount + 1; c = obj.pCount;end% Reset the counter to either a random value or the initial%值。functionresetImpl(obj)ifobj.UseRandomInitialValue obj.pCount = rand();elseobj.pCount = obj.InitialValue;endend% This method controls visibility of the object's propertiesfunctionflag = isInactivePropertyImpl(obj,propertyName)ifstrcmp(propertyName,'InitialValue') flag = obj.UseRandomInitialValue;else国旗= false;endendendend

参考