

% sin vector
f0 = 1;
N = 100;
x = [0:N-1];

% running gui M file, get the figure handle
M = M_gui;
g = guidata(M);
ga = g.axes1;

f_cnt = g.f_cnt;
old_f_cnt = f_cnt;

f = f0*f_cnt;
y = sin(f*x/N);
plot(ga, x, y);
grid(ga,'minor');

while 1
  % use guidata(), get data from figure handle
  g = guidata(M);
  f_cnt = g.f_cnt;
  % ga = g.axes1;
  if(f_cnt ~= old_f_cnt)
    f = f0*f_cnt;
    y = sin(f*x/N);
    plot(ga, x, y);
    grid(ga,'minor');
    old_f_cnt = f_cnt;
  end
  drawnow
  %pause(1E-2);
  
end
