Canonical method for setting graphics properties in MATLAB 2014b?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!