Canonical method for setting graphics properties in MATLAB 2014b?
Show older comments
Now that graphics handles are objects, I'm curious what folks would consider to be the canonical method for setting graphics properties. Here is an example from a recent answer of mine on this forum:
% Some data
x = 0:pi/10:pi;
y = sin(x);
% Create figure
figure
plot(x,y,x,2*y)
hL = legend({'1','2'});
% Get current position (which I used to keep overall size the same)
currentLegendPosition = hL.Position;
% Define new position
newLegendPosition = [0.5 0.5 currentLegendPosition([3 4])];
% Method 1 for setting new position
hL.Position = newLegendPosition;
% Method 2 for setting new position
set(hL,'Position',newLegendPosition)
The second method (pun intended) strikes me as the preferred one, because it actually uses a method ("set") of the object class, but I am curious about other opinions. I don't have much experience in object-oriented languages.
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!