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

39 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Orion
Orion am 17 Dez. 2014
Bearbeitet: Orion am 17 Dez. 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)

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by