how to count in a non-uniform pattern

Hi everyone, I have a question that I've been stumped for quite some time. I have some data that has associated to it a month, day, and hour. My problem arises when I need to count how many data are associated to month 1, day 1, and hour 0; to month 1, day 1, and hour 1; and so on. The problem is that there could be 4 datapoints associated to hour 0 but 9 datapoints associated to hour 1. I tried to use simple counts, for loops but couldn't come up with anything. Any help will be greatly appreciated.
The data looks like this just in case
1000
12 | 3 | 4 | 20 | 2008
1 | 1 | 0
1010
20 | 4 | 13 | 2008
1 | 1 | 0
950
20 | 2 | 2 | 2008
1 | 1 | 1
So summarizing I would need to count that for hour 0 there are 2 datapoints and for hour 1 there's only 1 data point. The hours are in bold, and are the last of the three 1 or 0 numbers on the line.
Thanks again.

1 Comment

Image Analyst
Image Analyst on 30 Oct 2012
Edited: Image Analyst on 30 Oct 2012
I assume 1000, 1010, and 950 are the data points and the stuff below represents the time code. But 12 | 3 | 4 | 20 | 2008 does not correspond to month, day, hour. You have 5 numbers and month, day, and hour would only be 3 numbers. What do each of the 5 numbers correspond to? What time period? It looks like the last one might be year, but that still leaves 4 numbers and 3 categories, assuming year is the last category.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 30 Oct 2012
Edited: Image Analyst on 30 Oct 2012
Can you somehow make a 2D numerical array out of all that, then call hist()? Or use textscan or fgetl() to read in only the n1|n2|n3 lines, get the third number and count it like you're doing the histogram
theLine = fgetl(fid);
if sum(theLine == '|')
% The line has exactly two vertical bars on it.
% Get the third number, say with textscan or sscanf. Then...
theHistogram(thirdNumber + 1) = theHistogram(thirdNumber + 1) + 1;
end
repeat until all lines have been read.

Categories

Asked:

on 30 Oct 2012

Community Treasure Hunt

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

Start Hunting!