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

18 ビュー (過去 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 Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by