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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

jonas
jonas am 16 Okt. 2018
Bearbeitet: jonas am 16 Okt. 2018
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by