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?

6 views (last 30 days)
Erica Corradi
Erica Corradi on 6 Aug 2018
Edited: jonas on 10 Aug 2018
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.
jonas on 6 Aug 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.

Sign in to comment.

Accepted Answer

jonas on 6 Aug 2018
Edited: jonas on 6 Aug 2018
From what you've described so far, a bar graph does not seem optimal. What about this approach instead?
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.
jonas on 10 Aug 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
figure;hold on
%%Some properties
w=0.2 %%Half bar width
y=[1 3] %%y-values of the bars
%%First plot
z=repmat([1 0],1,length(x)/2)
%%Repeat for second bar
x=out1.closing_opening'; %%I am reusing the same data
z=repmat([1 0],1,length(x)/2)
%%plot some markers for alarms
%%Change colors
map = [1 1 1
1 0 1
0 1 1
1 0 0
0 1 0
0 0 1
0 0 0];
view([0 90])
set(gca,'ylim',[0 5])
%set(h,'edgecolor','none') %If you want to remove edges

Sign in to comment.

More Answers (1)

Erica Corradi
Erica Corradi on 10 Aug 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?
jonas on 10 Aug 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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!