% working with handle graphics
% create a figure
figHandle = figure();

% retrieve some property of the figure
currentSize = get(figHandle,'Position');

% dot notation
currentSize2 = figHandle.Position;

% explicitly resize figure
set(figHandle,'Position',[10,20,500,600]);

%% consider x = 3*cos(t), y = 2*sin(3*t+2);

% set up variables
timeVector = linspace(0,20,300);
x = 3*cos(timeVector);
y = 2*sin(3*timeVector+2);

%% method 1: two 1D plots
clf();
subplot(2,1,1);
plot(timeVector,x,'rs:');
xlabel('time (new york minutes)');
ylabel('x (Camels per square mile)');
set(gca,'FontSize',18);

subplot(2,1,2);
plot(timeVector,y,'bx-');
xlabel('time (new york minutes)');
ylabel('y ($/bagel)');
set(gca,'FontSize',18);

%% method 2: one plot, overplotting
clf();

% predefine the plotting range
xRange = [min(x),max(x)];
yRange = [min(y),max(y)];

tic
for iiTime = 1:numel(timeVector)
   scatter(x(iiTime),y(iiTime),'ko');
   xlim(xRange)
   ylim(yRange);
   title(['t = ',num2str(timeVector(iiTime)),' new york minutes']);
   xlabel('x (Camels per square mile)');
   ylabel('y ($/bagel)');
   set(gca,'FontSize',18);

   drawnow;
    
end
toc

%% method 3: one plot, update positions
clf();

% predefine the plotting range
xRange = [min(x),max(x)];
yRange = [min(y),max(y)];

tic
scatterHand = scatter(x(iiTime),y(iiTime),'ko');
xlim(xRange)
ylim(yRange);
title(['t = ',num2str(timeVector(iiTime)),' new york minutes']);
xlabel('x (Camels per square mile)');
ylabel('y ($/bagel)');
set(gca,'FontSize',18);

for iiTime = 1:numel(timeVector)
    set(scatterHand,'XData',x(iiTime),'YData',y(iiTime));
    title(['t = ',num2str(timeVector(iiTime)),' new york minutes']);
    drawnow;
    
end
   toc


