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?

  • This could be helpful http://stackoverflow.com/questions/9781866/folder-and-folder – Alfabravo Jul 23 '14 at 17:15
  • @Alfabravo Thank you very much. I saw that answer before. It explains the hierarchy of folder for packages, and classes which I understand. But it does not clarify (as neither does the Matlab documentation) how to introduce new methods for existing classes. I guess subclassing is an option, but I would have to use a different name and that would require a good amount of re-coding. –  Jul 25 '14 at 10:55

1 Answers1

1

Since I had no luck trying to find a solution, I had to find one on my own. This is the method I came up with.

The toolbox had three new method for the zpk class. I created a new class, called sdzpk, and declared it to be a subclass of the built in zpk class. Then, wherever any of the new methods were used, I first converted the object to the new class before passing it to the method.

The following code may ilustrate that better:

Class definition file:

    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

At several locations within the toolbox, the function minreals is called. All those calls were replaced with:

    minreals(sdzpk(obj))

In that way, I make sure the new class is used and the correct method is applied.

I hope this helps somebody.