GUI Pushbutton

Hello, I am new to MATLAB. I am trying to implement a push button to plot an array of data. What i want the push button to do is plot a point every time it is pressed. I currently have the button set to where all of the points are plotted. How can i go about plotting each point individually instead of having the button plot everything from my data array?
function [] = send_call(varargin)%callback function
global i;
S = varargin{4}; % Get the structure.
i = i + 1;
ser = varargin{3}; % Get the structure.
a=[3,40,1,8,0,2,4,6,7,3,2,4,6,7,8,9,3,2]
c=[]
c(i) = a(i);
plot(c)
linkdata on %updates the graph
fprintf(ser,'%s',get(S.mesg,'string'));
end

Answers (1)

Grzegorz Knor
Grzegorz Knor on 28 Oct 2011
Do you mean something like this?
function test
x = 1:20;
y = sqrt(x)+randn(size(x));
plot(x,y,'--.')
hold on
uicontrol('Style','pushbutton','Units','normalized','Position',[.05 .05 .2 .1],...
'String', 'draw','callback',{@send_call,x,y})
function [] = send_call(varargin)%callback function
persistent i
if isempty(i)
i = 0;
end
x = varargin{3};
y = varargin{4};
i = i+1;
if i<=length(x)
plot(x(i),y(i),'ro')
else
warning('Index exceeds matrix dimensions.')
end

This question is closed.

Tags

Asked:

on 27 Oct 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!