The disp method uses fprintf to display formatted text in the command window:
methods
function disp(td)
fprintf(1,...
'Material: %s\nSample Number: %g\nModulus: %1.5g\n',...
td.Material,td.SampleNumber,td.Modulus);
end
end
Method to Plot Stress vs. Strain
It is useful to view a graph of the stress/strain data to determine the behavior of the
material over a range of applied tension. The TensileData class overloads the MATLAB
plot function.
The plot method creates a linear graph of the stress versus strain data and adds a title
and axis labels to produce a standardized graph for the tensile data records:
methods
function plot(td,varargin)
plot(td.Strain,td.Stress,varargin{:})
title(['Stress/Strain plot for Sample',...
num2str(td.SampleNumber)])
ylabel('Stress (psi)')
xlabel('Strain %')
end
end
The first argument to this method is a TensileData object, which contains the data.
The method passes a variable list of arguments (varargin) directly to the built-in plot
function. The TensileData plot method allows you to pass line specifier arguments or
property name-value pairs.
For example:
td = TensileData('carbon steel',1,...
[2e4 4e4 6e4 8e4],[.12 .20 .31 .40]);
plot(td,'-+b','LineWidth',2)
Representing Structured Data with Classes