Binning time-dependent data in a histogram

4 次查看(过去 30 天)
So, my data looks something like this: t1 = (1, 5, 8, 9), t2 = (2, 7, 9, 12), t3 = (2, 5, 5)
Each of the values is a datapoint; I'm measuring the time when the datapoint occured (so, in t1, datapoint 2 is occuring at timepoint 5s for example).
I want to combine all trails in one histogram, whos x-axis are timebins, so that I know how many datapoints I have at timepoint 2 sec, taken all the trails together.
So far, I put all my trails in one structure, but I can't get them aligned so that I can compute how many datapoints I have for a certain timepoint. I hope someone can help. It's driving me crazy, that I can't figure it out. :(

回答(2 个)

Peter Manley-Cooke
Peter Manley-Cooke 2011-6-28
If the data is in vectors, then
t1 = [1 5 8 9];
t2 = [2 7 9 12];
t3 = [2 5 5];
% Combine the data
t= [t1 t2 t3];
% put it in a histogram
hist(t,max(t));
% or collect data about the histogram
[N B] = hist(t,max(t));
will show a histogram with seconds on the x axis. As shown in the documentation, N is the number of items in each bin and B is the value of the bin centre.

Fangjun Jiang
Fangjun Jiang 2011-6-28
I don't understand. The code below shows a histogram. It shows at time t=2 and t=5, there are 3 data points. At time t=9, there are two data points. The rest, there is one data points. Is this what you want? Or you just couldn't get structure data together? What does your structure data look like?
t1=[1 5 8 9];
t2=[2 7 9 12];
t3=[ 2 5 5];
t=[t1 t2 t3];
hist(t);

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by