0

This is the error it returns: You cannot get the 't' property of Planet.

Error in Problem4dot10 (line 12) name=mercury.t(mercury);

I created getter functions to return properties of the class planet:

methods %for getter functions
        function t=get.t(obj)
            t=obj.t;
        end
        function r=get.r(obj)
            r=obj.r;
        end
        function x=get.x(obj)
            x=obj.x;
        end
        function y=get.y(obj)
            y=obj.y;
        end
        function vx=get.vx(obj)
            vx=obj.vx;
        end
        function vy=get.vy(obj)
            vy=obj.vy;
        end
        function n=get.n(obj)
            n=obj.n;
        end
        function n=get.Name(obj)
            n=obj.Name;
        end
    end

And I called the getter from the file Problem4dot10.m:

mercury=Planet(1,0.002,0,2*pi,1,0,'Mercury');
mercury.sett(60);
name=mercury.t(mercury);

I looked at the documentation to try to figure out it out. What I'm trying to do is create a planet class that keeps track of the position of the planet, and also calculates where the planet is in the next time step. It then assumes that new state.

user3273814
  • 198
  • 3
  • 16

1 Answers1

0

It seems to me that the t property is private. You can make it public using, e.g.:

properties(SetAccess = public, GetAccess = public)
    t = 0;
end

or

properties(Access = public)
    t = 0;
end

Also you don't need to pass mercury into t getter method. name=mercury.t; should be enough.

Marcin
  • 215,873
  • 14
  • 235
  • 294