MATLAB Object-oriented programming get and set method to realize _matlab

Source: Internet
Author: User

In MATLAB object-oriented programming, set and get are the methods of redefining parameter setting and querying function, similar to similar functions in Java. In the way of implementation, there is a little difference. In addition, in the implementation of the way, there is no time to find that MATLAB can be directly like in eclipse to edit the Java code to generate the default method.

Write a simple example demonstrating set and get functionality, creating the following classes:

ClassDef Getsetdemo

Properties

Ge

Shi

Bai

End

Methods

function obj = Getsetdemo (g,s,b)

obj.ge = g;

Obj.shi = s;

Obj.bai = b;

End

function value = get.ge (obj)

value = obj.ge;

End

function value = Get.shi (obj)

value = Obj.shi;

End

function value = Get.bai (obj)

value = Obj.bai;

End

function obj = set.ge (obj,value)

obj.ge = value * 1;

End

function obj = Set.shi (obj,value)

Obj.shi = value * 10;

End

function obj = Set.bai (obj,value)

Obj.bai = value * 100;

End

End

End

Use this class to create an object:

>> GS = Getsetdemo (1,2,3)

GS =

Getsetdemowith Properties:

Ge:1

Shi:20

bai:300

>> gs.ge

Ans =

1

>> Gs.shi

Ans =

20

>> Gs.bai

Ans =

300

      by the above results, we can see that the default set and get methods are covered by our own design methods.

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.