How do properties work in Object Oriented MATLAB?

前端 未结 3 609
花落未央
花落未央 2020-11-29 07:05

I am trying to create a MATLAB class with a member variable that\'s being updated as a result of a method invocation, but when I try to change the property within the class

3条回答
  •  有刺的猬
    2020-11-29 08:00

    I made the class testprop and tried to excute the code which Azim suggested but it did not work. When I executed the following command:

    a=a.Request(1)
    

    The following error was generated:

    ??? Error using ==> Request Too many output arguments.

    I think the problem is that we did not determine any output when declaring Request method. So we should change it to:

    function this = Request(this, val)
    

    and now:

    >> a = testprop;
    >> a = a.Request(1);        
    >> a.numRequests
    
    ans = 1
    

提交回复
热议问题