3

I inherited a complete toolbox, last revised in 2006, and I must update it to the latest version of Matlab. This toolbox defines some classes and defines methods for built in classes. More specifically, it creates some extra methods for objects of the control systems toolbox classes lti, ss, zpk and tf.

The first part, rebuilding the new classes, is already done. I am having troubles with the new methods for existing classes.

Since the code was written in an older version of Matlab, it uses class folders like @lti, @ss, @zpk to define the new methods. Now I need to keep the functionality, but using the new OOP model, in which not all @-folders are visible.

Does anybody know how to do that?

4

1 回答 1

1

由于我没有运气试图找到解决方案,我不得不自己找到一个。这是我想出的方法。

该工具箱为 zpk 类提供了三个新方法。我创建了一个名为 sdzpk 的新类,并将其声明为内置 zpk 类的子类。然后,在使用任何新方法的地方,我首先将对象转换为新类,然后再将其传递给方法。

以下代码可以更好地说明这一点:

类定义文件:

    classdef sdzpk < zpk & sdlti

        methods (Access = public)

            function obj = sdzpk(varargin)

                % Constructor method. Long code here to perform data validation
                % and pass information to the zpk constructor

                obj = obj@zpk(args{:});
            end

            % Existing methods
            % This are the old files I inherited. No need to edit them.

           tsys = ctranspose(sys);
           sys = delay2z(sys);
           sysr = minreal(sys,tol);
           F = minreals(F,tol);
           FP = setpoles(F,p);
           F = symmetr(F,type,tol);
           F = z2zeta(F,tol);
        end       
    end

在工具箱中的几个位置,调用了 minreals 函数。所有这些调用都替换为:

    minreals(sdzpk(obj))

这样,我确保使用了新类并应用了正确的方法。

我希望这对某人有所帮助。

于 2014-07-29T15:11:41.943 回答