非アクティブなプロパティの非表示
アクティブな System object™ プロパティのみを表示するには、isInactivePropertyImpl
メソッドを使用します。このメソッドは、プロパティが非アクティブかどうかを指定します。"非アクティブなプロパティ"は、他のプロパティの値があるために、System object に影響しないプロパティです。isInactiveProperty
メソッドをプロパティに渡し、このメソッドがtrue
を返すと、そのプロパティは非アクティブであり、関数disp
の呼び出し時に表示されません。
非アクティブなプロパティの指定
この例では、isInactiveProperty
メソッドを使用して、依存プロパティの値を確認します。この System object のUseRandomInitialValue
が true に設定されている場合、InitialValue
プロパティは関係ありません。このisInactiveProperty
メソッドはその状況を確認し、UseRandomInitialValue
がtrue
の場合は、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