Plotting 3 differing intervals of time in a bar style to show when an interval is occuring

1 次查看(过去 30 天)
I have 3 intervals of time (attached as data matrix - subdivided into a,b,c). These intervals divide the timeline (attached as time matrix) based on other data not attached. I would like to plot the data in a bar under the timeline to show when each interval is occurring. I have attached an example of something I would like it to look like, although the real data is randomly interspersed.
Please let me know if something is not clear. Any help would be greatly appreciated.

采纳的回答

jonas
jonas 2018-10-16
编辑:jonas 2018-10-16
I'll admit that I misunderstood the question the last time it was posted. However, the general approach still works the same.
%Load data
data = load('data matrix.mat');
t = load('time matrix.mat');
% Concatenate a,b,c with grouping variable
ts = [data.a,ones(size(data.a,1),1);data.b,ones(size(data.b,1),1).*2;data.c,ones(size(data.c,1),1).*3];
% Sort and make continous
ts = sortrows(ts,1);
td = ts(:,2)-ts(:,1); %Durations
td = cumsum(td);
% Make surface bar
n=length(td);
X=[td';td'];
Y=[1.1.*ones(1,n);0.9.*ones(1,n)];
colormap(lines(3))
Z=ts(:,3)';
Z=[Z;Z];
surf(X,Y,Z)
view([0 90])
set(gca,'ycolor','none')
.
Does it look alright? Note that the black stripes are edges that divide segments. You can remove those by setting the 'edgecolor' to 'none' in the surf call, getting this instead:
  8 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by