How can I toggle data on and off a figure using radio buttons in a matlab GUI?
28 次查看(过去 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.
0 个评论
采纳的回答
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
2020-9-5
hi
could you please tell me where should i put the first part of the code you sent.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!