0

インスタンス変数が保存されない理由を理解するのに苦労しています。CurrentSettingsを変更しても、次に別の関数を呼び出したときに表示されません。基本的には保存せず0、各関数の後にsに戻ります。

classdef laserControl
%LASERCONTROL This module is designed to control the laser unit. 
%   It can set the filter position, open and close the shutter and turn
%   on/off the laser.
%
%%%%%%%%%%PORT LISTINGS%%%%%%%%%%%
%The set filter command is on port0
%The set shutter is in port1
%Laser 1 on port2
%Laser 2 on port3
%The filter digits are on ports 8-15 (the are on the second box)

properties%(GetAccess = 'public', SetAccess = 'private')
    laserPorts; %The #'s of the output ports
    currentSettings; %Current high/low settings
    dio;
end

methods

    %Constructor
    %Opens the connection with the digital outputs
    %Make sure to close the connection when finished
    function Lobj = laserControl()
        %Setup the laser
        Lobj.laserPorts = [0:3 8:15];% 8:15
        Lobj.currentSettings = zeros(1, length(Lobj.laserPorts));
        %Make connection and reset values
        Lobj.dio = digitalio('nidaq','Dev1');
        addline(Lobj.dio, Lobj.laserPorts, 'out');
        putvalue(Lobj.dio, Lobj.currentSettings);
    end

    %Closes the connection to the digital output
    function obj = CloseConnection(obj)
        putvalue(obj.dio, zeros(1, length(obj.currentSettings)));
        delete(obj.dio);
        clear obj.dio;
    end


    %Sets the position of the filter.
    %positionValue - the integer amount for the position, cannot be
    %larger than 150, as regulated by the box.
    %The set filter command is on port0
    %The filter digits are on ports 8-15 (the are on the second box)
    function obj = SetFilterPosition(obj, positionValue)
        if 0 <= positionValue && positionValue < 150
            binaryDigit = de2bi(positionValue); %Convert it to binary form
            %LaserOn OldSettings NewValue ExtraZeros
            obj()
            obj.currentSettings()
            obj.currentSettings = [1 obj.currentSettings(1, 2:4) binaryDigit...
                zeros(1, 8 - length(binaryDigit))];
            putvalue(obj.dio, obj.currentSettings);
        else
            display('Error setting the filer: Value invalid');
        end
    end
end
4

1 に答える 1

1

クラスはから継承しないためhandle、「値」タイプのクラスを作成しました。つまり、変更を加えるときは、次のように戻り値をキャプチャする必要があります。

myObj = SetFilterPosition( myObj, 7 );

ハンドルクラスと値クラスの詳細については、ドキュメントを参照してください

于 2012-07-11T07:15:54.050 に答える