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

조회 수: 37 (최근 30일)
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.

채택된 답변

Orion
Orion 2014년 12월 17일
편집: Orion 2014년 12월 17일
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)
  댓글 수: 2
farhad vaseghi
farhad vaseghi 2020년 9월 5일
hi
could you please tell me where should i put the first part of the code you sent.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by