make an example of an object oriented program in matlab

Here is an example of an object-oriented program in MATLAB:

main.m
%define a class 'Rectangle'

classdef Rectangle    
    properties
        height
        width
    end
    methods
        %constructor of the class
        function obj = Rectangle(h, w)
            obj.height = h;
            obj.width = w;
        end
        %method to calculate the area of the rectangle
        function A = area(obj)
            A = obj.height * obj.width;
        end
        %method to calculate the perimeter of the rectangle
        function P = perimeter(obj)
            P = 2*(obj.height + obj.width);
        end
    end
end


%creating an object of the class 'Rectangle'
r1 = Rectangle(4, 5);

%calculating area and perimeter of the rectangle
A1 = r1.area()
P1 = r1.perimeter()

%creating another object of the class 'Rectangle'
r2 = Rectangle(6, 8);

%calculating area and perimeter of the rectangle
A2 = r2.area()
P2 = r2.perimeter()
870 chars
39 lines

In this example, a class Rectangle is defined with two properties height and width. The class has a constructor to initialize the properties and two methods to calculate the area and perimeter of a rectangle.

Two objects r1 and r2 are created from the Rectangle class using the constructor. The area and perimeter methods are called on these objects to calculate their respective values.

gistlibby LogSnag