How to change a plot's graph with radiobutton and drawnow?
2 次查看(过去 30 天)
显示 更早的评论
Hello!
So i have an antenna which receives a signal and then plots the signal. I have a problem on how to make so that when i click on a radiobutton, the graph changes what to plot, i.e, make the signal amplitude bigger.
Here is the code:
figure;
%%%%%Buttons%%%
global h;
h = uibuttongroup('visible','off','Position',[0 0 .2 1]);
% Create two radio buttons in the button group.
u0 = uicontrol('Style','radiobutton','String','Option 1',...
'pos',[10 350 100 30],'parent',h,'HandleVisibility','off');
u1 = uicontrol('Style','radiobutton','String','Option 2',...
'pos',[10 250 100 30],'parent',h,'HandleVisibility','off');
set(h,'SelectionChangeFcn',@(source,eventdata,handles)selcbk);
set(h,'SelectedObject',[]); % No selection
set(h,'Visible','on');
%%%%Buttons end%%%
h = line(1:numCounters, frame);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Read and plot data from the radar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Continue reading frames as long as the plot window is valid
while(ishandle(h))
tic;
global c;
c = double(radar.GetFrameNormalizedDouble()); %Here we get the values from the antenna
set(h,'ydata',c);
drawnow
So the problem is, that how to make that the program plots the graph with the new values, i.e, c=c*2 when I click the second radiobutton and change back to the original signal when I click on the first one? I can't figure out how to use the callback function:
function selcbk(source,eventdata,handles)
set(h,'YData', c*2);
0 个评论
回答(1 个)
Geoff Hayes
2016-3-5
Raitis - I would avoid using the callback to the radio button and just check the state of the radio button in the while loop. If it is enabled, then multiply c by two. For example
% Continue reading frames as long as the plot window is valid
while(ishandle(h))
tic;
c = double(radar.GetFrameNormalizedDouble()); %Here we get the values from the antenna
if get(u1,'Value')
c = c*2;
end
set(h,'ydata',c);
drawnow;
end
Try the above and sees what happens!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!