Canonical method for setting graphics properties in MATLAB 2014b?
이전 댓글 표시
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!