How can I toggle data on and off a figure using radio buttons in a matlab GUI?
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Orion
le 17 Déc 2014
Modifié(e) : Orion
le 17 Déc 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)
2 commentaires
farhad vaseghi
le 5 Sep 2020
hi
could you please tell me where should i put the first part of the code you sent.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!