user3869571
user3869571

Reputation:

Extending matlab classes: new methods for built-in classes

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?

Upvotes: 3

Views: 574

Answers (1)

user3869571
user3869571

Reputation:

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.

Upvotes: 1

Related Questions