How can I swith between plots in the same plot window?

조회 수: 20 (최근 30일)
Madina Makhmutova
Madina Makhmutova 2018년 3월 24일
댓글: Madina Makhmutova 2018년 4월 20일
I have a time-lapse matrix. Each column is a region of interest (Roi) and each row is the time point value. I need to quickly visualize each trace individually. Is there a way to plot all the traces at the same time but have only one at a time selected for visualization so I can move quickly through the traces just by clicking the up/down buttons to move through selections?

채택된 답변

Rik
Rik 2018년 3월 24일
편집: Rik 2018년 3월 25일
You can plot all the lines and toggle the visibility with the KeyPressFcn of the figure, which sets the Visible property of the line objects that plot returns.
Edit: see an example below
f=figure(1);clf(1)
h=plot(rand(4,2));axis([1 3 0 1])
handles=struct('f',f,'h',h);
handles.visible_index=1;%keep track of which plot is selected
set(h,'Visible','off');
set(h(handles.visible_index),'Visible','on');
guidata(f,handles)
set(f,'KeyPressFcn',@SetVisibility)
function SetVisibility(hObject,eventdata)
switch eventdata.Key
case {'uparrow','up'}
direction=1;
case {'downarrow','down'}
direction=-1;
otherwise
return
end
handles=guidata(hObject);
%set the old plot to invisible
set(handles.h(handles.visible_index),'Visible','off');
%find the new index to be set
handles.visible_index=mod(handles.visible_index+direction,length(handles.h));
if handles.visible_index==0,handles.visible_index=length(handles.h);end
%set the new plot to visible
set(handles.h(handles.visible_index),'Visible','on');
%optional: set the title to the index value
title(sprintf('selected plot: %d',handles.visible_index))
guidata(hObject,handles)
end
  댓글 수: 4
Rik
Rik 2018년 4월 20일

Just as a note for future reference (in response to your email): I am receiving notifications, although I did choose to disable email notifications. That way I can keep track of the questions that get updates, but only when I have time to actually reply.

The code below is the adapted version. If you make sure h is a matrix where each row should be displayed simultaneously, this will do that for you. Don't forget to explicitly code a range for the axes (like I did with axis([1 4 0 1]) below). This will prevent the axes to jump around when you hide plots.

f=figure(1);clf(1)
y1=rand(4,2);
y2=rand(4,2);
y3=rand(4,2);
x=1:4;
h=plot(x,y1,'y',x,y2,'k',x,y3,'r');
h=reshape(h,2,3);
axis([1 4 0 1])
handles=struct('f',f,'h',h);
handles.visible_index=1;%keep track of which plot is selected
set(h,'Visible','off');
set(h(handles.visible_index,:),'Visible','on');
guidata(f,handles)
set(f,'KeyPressFcn',@SetVisibility)
function SetVisibility(hObject,eventdata)
switch eventdata.Key
    case {'uparrow','up'}
        direction=1;
    case {'downarrow','down'}
        direction=-1;
    otherwise
        return
end
handles=guidata(hObject);
%set the old plot to invisible
set(handles.h(handles.visible_index,:),'Visible','off');
%find the new index to be set
handles.visible_index=mod(handles.visible_index+direction,size(handles.h,1));
if handles.visible_index==0,handles.visible_index=size(handles.h,1);end
%set the new plot to visible
set(handles.h(handles.visible_index,:),'Visible','on');
%optional: set the title to the index value
title(sprintf('selected plot: %d',handles.visible_index))
guidata(hObject,handles)
end
Madina Makhmutova
Madina Makhmutova 2018년 4월 20일
Dear Rik,thank you very much! This works nicely!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by