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
0 个评论
回答(1 个)
Grzegorz Knor
2011-10-28
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
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!