[Guide, R2012b] Add or remove legend if plot visibility is switched On/Off

3 vues (au cours des 30 derniers jours)
Michael Daldini
Michael Daldini le 21 Nov 2017
Commenté : Michael Daldini le 21 Nov 2017
Hey everyone,
I am having problems to find the right command lines to update the axes with the selected shown plots. My Gui allows to show which plots are shown by using a system of checkboxes
The checkboxes are in a uitable and the callback function fro the CellEditCallback is the following:
function fctTable(hObject, eventdata)
handles = guidata(hObject);
if eventdata.Indices(2) == 1
if eventdata.NewData == 0
set(handles.plots{eventdata.Indices(1)}, 'visible', 'off');
else
set(handles.plots{eventdata.Indices(1)}, 'visible', 'on')
end
end
guidata(hObject, handles);
end
% --- Executes on button press in PB_load.
function PB_load_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
[FileName,PathName] = uigetfile('*.txt');
if FileName == 0
return
else
cla(handles.axes1);
[~, name] = fileparts(FileName);
fileName = fopen(fullfile(PathName, FileName),'r');
C = textscan(fileName,...
'%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s',...
'Delimiter', ';');
end
for i = 1:length(C)
handles.colors{i}= rand(1,3);
end
.
.
.
a = 1;
for i = 1:2:15
handles.plots{a} = plot(A, channel(a).current, 'color',...
handles.colors{i},'DisplayName', strcat('channel\_', num2str(a-1)));
a = a+1;
end
legend('show');
guidata(hObject, handles)
end
I will attach the files if someone want to try the code.
Thanks in advance.
michael
  1 commentaire
Michael Daldini
Michael Daldini le 21 Nov 2017
This is how I have solved it:
I have created a pushbutton to update the legend, having the following callback fct:
function PB_UpdateLegend_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
table = get(handles.uitable1, 'Data');
idx = find([table{:,1}] == 1);
legend([handles.plots{idx}], {handles.legend{idx}});
guidata(hObject, handles);
end
As always I attach the files to test the code if you want to sue the same system

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur App Building 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!

Translated by