MATLAB Object-Oriented Programming

(Joyce) #1
Year
end
properties(Transient)
Chart
end
properties(Access = private)
ChartData
end
methods
function rf = YearlyRainfall(data)
setup(rf,data);
end
function set.ChartData(obj,V)
setup(obj,V);
end
function V = get.ChartData(obj)
V = obj.Chart.YData;
end
end
methods(Access = private)
function setup(rf,data)
rf.Chart = bar(data);
end
end
end

Change to a Stairstep Chart


An advantage of the YearlyRainfall class design is the flexibility to modify the type of
graph used without making previously saved objects incompatible. Loading the object
recreates the graph based only on the data that is saved to the MAT-file.

For example, change the type of graph from a bar chart to a stair-step graph by modifying
the setup method:

methods(Access = private)
function setup(rf,data)
rf.Chart = stairs(data);
end
end

13 Saving and Loading Objects

Free download pdf