Matlab Object-Oriented Programming learning notes (i) _matlab object-oriented programming learning notes

Source: Internet
Author: User

Hierarchical structure of code:

+foddername This is the package name and defines a namespace for its internal content

@classname This is the class folder, and the folder name is the class name

CLASSNAME.M this file as the primary class

FUNCTIONNAME.M this file as a class function file

You can place the keynote function on the outermost layer, which is parallel to the package name.


Main class Code structure

ClassDef (constructonload=true,sealed) myclock  
    in the command window enter t= myclock (8,30,20) Run program
    %constructonload=true, The constructor of the object is called when the class is loaded.
    Properties
        Hour;   % when
        Minute;    %
        Second;   % sec
    End
    methods
        function Obj=myclock (h,m,s)  % constructor
            obj. Hour=h;
            Obj. minute=m;
            Obj. Second=s;
        End
        function Show (obj)
            disp [Num2str (obj. Hour), ': ',...
                Num2str (obj. Minute, ': ', num2str (obj. Second)]);
        End
        Function value = Get. Hour (object)
            value = obj. Hour;
            Disp (' Querying Hour value ')
        end
        Function obj = set. Hour (Obj,value)
            if~ (value>0)
                error (' property value must is positive ')
            else
                obj. Hour = value;
            End
            disp (' Setting Hour value! ')
        End
        
    End


Properties define Variables

The

methods defines a method in which the same function as the class name is a constructor.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.