How to change a plot's graph with radiobutton and drawnow?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Geoff Hayes
on 5 Mar 2016
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 Comments
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!