Here's a small GUI, the main part is ln_button and in particular you have to customize what happens at its end, I just plot some random numbers.
keyPressFcn and moveArrow are just there to make it fancy, you don't need to click the graph but you can browse the graph with arrow keys.
Also, you could speed it up by creating a line object s.ln(3) in the first axis, assign it a dummy value and then just substitute the plot with a set(s.ln(3),'Ydata',...,'Xdata',...).
% Figure
s.fh = figure('Units','pixels','Pos',[200 100 800 600],...
'Numbert','off','Menubar','none','KeyPress',@keyPressFcn);
s.a(1) = axes('Units','pixels','Pos',[60 50 680 210]);
s.a(2) = axes('Units','pixels','Pos',[60 350 680 210],'Xlim',[1,100]);
% Line object in first axis
s.ln(1) = line(1:100,(.1:.1:10) + rand(1,100),...
'lines','none','marker','.','markers',5,...
'markere','k','buttond',{@ln_buttond});
s.ln(2) = line(-1,-1,'lines','none','marker','o',...
'markere','r','markers',5);
% ln_buttond --------------------------------------------------------------
function ln_buttond(varargin)
XY = get(s.ln(1),{'Xdata','Ydata'});
if isempty(varargin{end})
cpaxes = get(s.a(2),'currentpoint');
idx = abs(cpaxes(1) - XY{1}) < .5;
else
idx = varargin{end};
end
set(s.ln(2),'Ydata',XY{2}(idx),'Xdata',XY{1}(idx));
plot(s.a(1),rand(100,1),rand(100,1))
end
% keyPressFcn -------------------------------------------------------------
function keyPressFcn(varargin)
switch upper(varargin{2}.Key)
case 'LEFTARROW'
moveArrow(-1)
case 'RIGHTARROW'
moveArrow(+1)
end
end
% moveArrow ---------------------------------------------------------------
function moveArrow(step)
X = get(s.ln(2),'Xdata');
X = X + step;
Xlimits = get(s.a(2),'Xlim');
if X >= Xlimits(1) && X <= Xlimits(2)
ln_buttond(X)
end
end
end
Best Answer