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

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.

 Respuesta aceptada

jonas
jonas el 16 de Oct. de 2018
Editada: jonas el 16 de Oct. de 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 comentarios

Is it possible that the first time intervals are listed, then the second, then the third instead of them being interspersed?
It seems that all the time intervals from the first matrix are being plotted, then all the intervals from the second and so forth instead of them being plotted interspersed depending on when they are occurring?
ops.. it should say
ts = sortrows(ts,1);
instead of
ts = sort(ts);
the latter sorts all column whereas we only want to sort with respect to the first column.
Any advice on how to show legend for only the three different set of intervals?
Sure, I'd just add something like this
for j = 1:3
p(j) = patch(min(X(:)),1.1,cmap(j,:))
end
legend(p,'location','eastoutside')
axis tight
creating a 'fake' legend. The surface is only one object, so you cannot get three legend entries without some hacky solution.
Ok, what does the variable 'cmap' refer to?
Ops, add cmap before the call to colormap
cmap = colormap(...)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 16 de Oct. de 2018

Comentada:

el 17 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by