0

以下に示すように、MobileBaseStation というクラスと、構造体である DataChannel というプロパティを定義する必要があります。

classdef MobileBaseStation
properties
    DataChannel = struct('TxScheme','SpatialMux','NLayers',4);
end
properties (Constant = true)
    supportedTxSchemes = {'Port0','TxDiversity','CDD','SpatialMux','MultiUser','Port5','Port7-8','Port8','Port7-14'};
end
methods
    function this = MobileBaseStation(this,TxSchemeChoice,NLayers)
        this.DataChannel.TxScheme = TxSchemeChoice;
        this.DataChannel.NLayers = NLayers;
    end
    function this = set.DataChannel.TxScheme(this,value)
        if ismember(value,this.supportedTxSchemes)
            this.DataChannel.TxScheme = value;
        end
    end
    function this = set.DataChannel.NLayers(this,value)
        if strcmpi(this.TxScheme,'Port8') && value==1
            set.DataChannel.NLayers = value;
        end
    end
end
end

セッターは、DataChannel 構造体のフィールドに境界/制限を適用する必要があります。セッターを使用できるように、構造体のフィールドを MobileBaseStation クラスのプロパティにする必要があります。Matlabでこれを達成するにはどうすればよいですか?

4

1 に答える 1

0

DataChannel依存プロパティのゲッターとセッターを介してアクセスを制御できるように、プライベートにしたいと思います。

classdef MobileBaseStation
    properties(GetAccess=private, SetAccess=private)
        DataChannel = struct('TxScheme','SpatialMux','NLayers',4);
    end

    ...

    properties(Dependent=true)
        TxScheme;
        NLayers;
    end

    methods
        function v = get.TxScheme(this), v = this.DataChannel.TxScheme; end
        function v = get.NLayers(this), v = this.DataChannel.NLayers; end

        function this = set.TxScheme(this,v)
            assert(ismember(v,this.supportedTxSchemes),'Invalid TxScheme - %s.',v);
            this.DataChannel.TxScheme = v;
        end

        ...
    end
end
于 2016-02-17T14:27:01.073 に答える