MATLAB Object-Oriented Programming

(Joyce) #1
Data Description
Material char vector identifying the type of material tested
SampleNumber Number of a particular test sample
Stress Vector of numbers representing the stress applied to
the sample during the test.
Strain Vector of numbers representing the strain at the
corresponding values of the applied stress.
Modulus Number defining an elastic modulus of the material
under test, which is calculated from the stress and
strain data

The TensileData Class


This example begins with a simple implementation of the class and builds on this
implementation to illustrate how features enhance the usefulness of the class.

The first version of the class provides only data storage. The class defines a property for
each of the required data elements.

classdef TensileData
properties
Material
SampleNumber
Stress
Strain
Modulus
end
end

Create an Instance and Assign Data


The following statements create a TensileData object and assign data to it:

td = TensileData;
td.Material = 'Carbon Steel';
td.SampleNumber = 001;
td.Stress = [2e4 4e4 6e4 8e4];
td.Strain = [.12 .20 .31 .40];
td.Modulus = mean(td.Stress./td.Strain);

3 MATLAB Classes Overview

Free download pdf