how do I plot input / output data so as to have a continuous bar in that range and not two simple points for each output / input?

1 visualización (últimos 30 días)
Hello everyone! I have the following datetime vector, which contains the time (date and time) in which the patient has been away from home. The odd rows correspond to the moment he left the house, the even rows correspond to the moment he returned home. How do I make a horizontal bar graph in which there is time in the x axis and my vector in the y axis, so as to obtain continuous bars for the "out-entered" time intervals (in red in the figure)? Thanks in advance.
  3 comentarios
jonas
jonas el 6 de Ag. de 2018
Does it have to be a bar graph? You can make a stacked horizontal bar with barh, but it's extremely slow. You could get similar results using plot, which would be much more effecient.

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 6 de Ag. de 2018
Editada: jonas el 6 de Ag. de 2018
From what you've described so far, a bar graph does not seem optimal. What about this approach instead?
in=load('closing_opening.mat')
t=in.closing_opening;
t=reshape(t,2,length(t)/2)'
h=plot(t',ones(size(t))');
set(h,'linewidth',4);
It basically outputs what you showed in your sketch. Change the y-tick to your label of choice. If you want to plot multiple arrays, just make a for loop with a variable y-coordinate.
  4 comentarios
Erica Corradi
Erica Corradi el 10 de Ag. de 2018
If I want to add to my bar (closing_opening) other data coming from another table (called pir_tab_night), how do I do it? I also want to add another bar (below the first one) that contains all the various alarms (contained in a further table, called tab_alarms_night). Regarding the pir_tab_night, the names of the pir sensors (which will appear in the first graph with different colors) can be found in the column called Column1streamId; while, regarding the tab_alarms_night, the types of alarm (which will appear in the second graph with different colors) can be found in the column called Column1type. I would also like to have the following colors: for the first bar graph
green, closing_opening;
red, dbuid-17;
brown, dbuid-21;
cyan, dbuid-20;
magenta, dbuid-18;
blue, dbuid-19;
while for the second bar:
red, alarm/personleaving;
blue, alarm/flood;
black, alarm/smoke;
green, alarm/nobedreturn. Thanks in advance!!!
jonas
jonas el 10 de Ag. de 2018
Editada: jonas el 10 de Ag. de 2018
Okay, this is a bit more complicated than the original question but I'll try. Note that I've used the other method that I linked my previous comment. It's faster and looks better.
I've written something to start with. However, I really don't understand how pir_tab_night is structured, what it means, and how it relates to the other two .mat files you attached.
You can easily change color of individual bars, but the colors relate to the Z-value and the colormap.
%%Load data
out1=load('closing_opening.mat')
out2=load('tab_alarms_night.mat')
figure;hold on
%%Some properties
w=0.2 %%Half bar width
y=[1 3] %%y-values of the bars
%%First plot
x=out1.closing_opening';
x=[x;x];
y1=y(1);
y1=[(y1+w).*ones(1,length(x));(y1-w).*ones(1,length(x))];
z=rand(1,length(x));
z=repmat([1 0],1,length(x)/2)
z=[z;z];
h=surf(x,y1,z)
%%Repeat for second bar
x=out1.closing_opening'; %%I am reusing the same data
x=[x;x];
y1=y(2);
y1=[(y1+w).*ones(1,length(x));(y1-w).*ones(1,length(x))];
z=rand(1,length(x));
z=repmat([1 0],1,length(x)/2)
z=[z;z];
h=surf(x,y1,z)
%%plot some markers for alarms
x2=out2.tab_alarms_night;
y2=mean(y1(:))-0.3
[G,id]=findgroups(x2.Column1type)
hl=splitapply(@plot,x2.t,y2.*ones(length(x2.t),1),G)
%%Change colors
set(hl(1),'color','r','linestyle','none','marker','x')
set(hl(2),'color','b','linestyle','none','marker','x')
legend(hl,cellstr(id))
map = [1 1 1
1 0 1
0 1 1
1 0 0
0 1 0
0 0 1
0 0 0];
colormap(map)
view([0 90])
set(gca,'ylim',[0 5])
colorbar
%set(h,'edgecolor','none') %If you want to remove edges

Iniciar sesión para comentar.

Más respuestas (1)

Erica Corradi
Erica Corradi el 10 de Ag. de 2018
The plot is great fine, thank you very much! I can put only the first plot since the alarms are below of it. If I wanted to put together the pir_tab_night and the closing_opening in the first plot, how should I write?
  5 comentarios
Erica Corradi
Erica Corradi el 10 de Ag. de 2018
I attached a drawing to make you understand how I would like the chart: the "dbuid-xx" are in the pir_tab_night table, in the column "Column1streamId". Each number relative to the "dbuid-xx" represents a specific room of the home of the analyzed subject. The vector that I called closing_opening represents the exits from home of the subject. So I would to obtain one bar that contains all these information: where is the subject when he stay at home; when and how long the subject stay away from home.
jonas
jonas el 10 de Ag. de 2018
Editada: jonas el 10 de Ag. de 2018
Okay, I kind of get it. In the closing_opening you have a green bar when the person is away (if I remember correctly). In the other one, you have a bunch of time-slots with different sensor names. As the code is written now, the time between those slots are marked in different colors. Sometimes there is a big gap in the pir-time-series, I assume this means the person is away from home?
Obvious solution is to concatenate both data sets into a single large timetable, with a special identifier for closing_opening. I've done this, and it looks quite OK. If my understanding is correct, this situation should never occur:
subject leaves
motion detected
subject returns
In fact, subject leaves should always be followed by subject returns, with no motion detected in between. I've checked the combined timetable and it looks OK so far (open_closing always occur in pairs).
But what about this sequence:
12-Mar-2018 06:59:55 dbuid-17
12-Mar-2018 06:59:58 dbuid-19
12-Mar-2018 09:57:47 open_close
12-Mar-2018 11:09:40 open_close
12-Mar-2018 13:45:31 open_close
12-Mar-2018 15:50:14 open_close
12-Mar-2018 21:02:31 dbuid-19
12-Mar-2018 21:02:36 dbuid-19
12-Mar-2018 21:02:40 dbuid-19
It seems motion is detected - subject leaves - subject comes back - subject leaves - subject comes back - motion detected 6 hours later. I don't know what this means, but be cautious with the interpretation.
Attached is a code you can start from. It will give you something similar to what you drew. Since the data set is now so large, there is no chance for me to check if it's correct.
I'll consider this closed now. If you have any other question, please post a new submission and make sure the problem is well stated. General advice: don't throw a bunch of data on someone who is trying to help with the technical aspects of MATLAB. Make it easy by condensing the data set down to a few lines.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by