Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:13:31+00:00 2026-06-08T19:13:31+00:00

I want to create a subclass, ess say, to the built-in ss class. I’d

  • 0

I want to create a subclass, ess say, to the built-in ss class. I’d like to be able to convert an existing ss object to an ess object and at the same time add the missing properties, e.g. w, by something like this

sys=ss(a,b,c,d);
esys=ess(sys,w);

but I can’t figure out how to setup the constructor correctly. What is the best way to achieve this? My code currently looks like this

classdef ess < ss
    properties
        w
    end
    methods
        function obj = ess(varargin)
            if nargin>0 && isa(varargin{1},'StateSpaceModel')
                super_args{1} = sys;
            else
                super_args = varargin;
            end
            obj = obj@ss(super_args{:});
        end
    end 
end

But this does not work as I get the following error:

 >> ess(ss(a,b,c,d))
 ??? When constructing an instance of class 'ess', the constructor must preserve
 the class of the returned object.

Of course I could copy all the object properties by hand but it seems to me that there should be some better way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:13:33+00:00Added an answer on June 8, 2026 at 7:13 pm

    Here is an example of what I had in mind:

    classdef ss < handle
        properties
            a
            b
        end
    
        methods
            function obj = ss(varargin)
                args = {0 0};     %# default values
                if nargin > 0, args = varargin; end
                obj.a = args{1};
                obj.b = args{2};
            end
        end
    end
    

    and:

    classdef ess < ss
        properties
            c
        end
    
        methods
            function obj = ess(c, varargin)
                args = {};
                if nargin>1 && isa(varargin{1}, 'ss')
                    args = getProps(varargin{1});
                end
                obj@ss(args{:});    %# call base-class constructor
                obj.c = c;
            end     
        end
    end
    
    %# private function that extracts object properties
    function props = getProps(ssObj)
        props{1} = ssObj.a;
        props{2} = ssObj.b;
    end
    

    Lets test those classes:

    x = ss(1,2);
    xx = ess(3,x)
    

    I get:

    xx = 
      ess handle
    
      Properties:
        c: 3
        a: 1
        b: 2
      Methods, Events, Superclasses
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class Dad with subclass Son . I'd like to create a subclass
I want to create an object that acts as a specific class, such as
According to this answer I want to create my own subclass of Array QArray
Let's say I make a major class Car - and I want this class
I want to create an abstract class in java that forces all its subclasses
I want to create a class with two methods, and no other purpose than
I want to create a method in superclass of test-class that stubs some commonly
Let's say you want to diagram a Map class (the mathematical kind, not the
Having a object x which is an instance of some class how to create
I want to create a class that can take different types of value in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.