How can I toggle data on and off a figure using radio buttons in a matlab GUI?

27 views (last 30 days)
I am trying to make a GUI that plots multiple data sets on a single plot. I need each dataset to be assigned to its own radio button so the user can select what data they want to display on the plot. I also what the user to be able to de-select a dataset by unchecking the corresponding radio button. I can't seem to selectively remove the dataset I want when unticking the relevant radio button. I can only figure out a way to clear the whole plot, which is not what I want. I have attached a picture of what my code looks like. Any help would be great.

Accepted Answer

Orion
Orion on 17 Dec 2014
Edited: Orion on 17 Dec 2014
you could create and stock the plots inside the handles structure and then make them visible or not according to the toggle button value.
piece of code :
x = 0:0.01:20;
y1 = sin(x);
y2 = cos(x);
handles.figure = figure;
hold on;
handles.plot1 = plot(x,y1,'b');
handles.plot2 = plot(x,y2,'r');
% visible / not visible
pause(0.5);
set(handles.plot2,'visible','off')
pause(0.5);
set(handles.plot1,'visible','off')
pause(0.5);
set(handles.plot2,'visible','on')
pause(0.5);
set(handles.plot1,'visible','on')
In your code, you should do something like :
function button1_callback(hObject,evendata,handles)
if ~isfield(handles,'plot1')
Data = csvread('Data.csv');
X = Data(:,2);
Y = Data(:,1);
handles.plot1 = plot(X,Y,.....); % every option
end
h = get(handles.button1,'Value');
if h==1
set(handles.plot1,'visible','on')
else
set(handles.plot1,'visible','off')
end
guidata(gcf,handles)

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!