Choice between legends and curves

Hi,
I have in one plot more curves.
If I press pushbutton1, then I need to show off legend1 and also curve1. If I press again pushbutton1, then I need to show on legend1 and also curve1.
If I press pushbutton2, then I need to show off legend2 and also curve2.If I press pushbutton2, then I need to show on legend2 and also curve2. . . . Please, can you help me

2 comentarios

john
john el 11 de Abr. de 2013
How can I close axis 1? If I use this code:
for i=1:7
handles.speed(:,i)=(s/t)';
plot(t',handles.speed);
cla(handles.speed(:,1),'reset');
end;
I gor error Bad handle
john
john el 15 de Abr. de 2013
Can anybody help? Please?

Iniciar sesión para comentar.

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 15 de Abr. de 2013
Editada: Sean de Wolski el 15 de Abr. de 2013
Here is how I would go about this:
function showTwoLines
%two lines and their legend
hFig = figure;
hL(1) = plot(1:10);
hold on
hL(2) = plot(rand(1,10));
legend(hL, 'Line 1','Line 2')
%two pushbuttons. Note the callback passes in the line handles and the line of choice index.
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.1 0.05 0.3 0.1],...
'String','One!',...
'Callback',@(~,~)ToggleLines(hL,1));
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.4 0.05 0.3 0.1],...
'String','Two!',...
'Callback',@(~,~)ToggleLines(hL,2));
end
function ToggleLines(hL,idx)
set(hL(setdiff(1:numel(hL),idx)),'visible','off'); %turn other lines off
set(hL(idx),'visible','on'); %turn line of choice on
legend(hL(idx),sprintf('Line %i',idx)); %add legend
end
Save the above to showTwoLines.m

4 comentarios

john
john el 16 de Abr. de 2013
Editada: john el 16 de Abr. de 2013
Hi, I make code in gui.
I need use checkbox. I need generate for example 10 checkboxes. Count of checkboxes is always different.
How can I change your callback? If checkbox1 is one, then show line one. If it is off, then show off line one. Checkbox1 does not affect the others checkboxes.
Sean de Wolski
Sean de Wolski el 17 de Abr. de 2013
Hi John, I should have some time to augment the example later.
john
john el 18 de Abr. de 2013
OK, I will wait, thanks
john
john el 23 de Abr. de 2013
Is there anything new?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 9 de Abr. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by