|
"Justin " <jstinnet@uvm.edu> wrote in message <hvrq4l$64s$1@fred.mathworks.com>...
> Hello, I have a large dataset (100K+ rows) that has two time columns which represent a starting and ending time.
>
> I wish to know for each hour (from serial numbers timeStart = 37988; and timeEnd = 39966;) how many occurrence exist within the dataset start and end time columns where the time being analysed (time = timeStart:1/24:timeEnd;) falls between the start and end time of the dataset.
>
> This code does what I want but is not very elegant and takes way too long with larger datasets.
>
> function [count] = calcCensus(timeStart,timeEnd,dataIn)
> count = zeros(1,size(timeStart:1/24:timeEnd,2));
> nCount = 0;
> for n= timeStart:1/24:timeEnd
> n
> nCount = nCount + 1;
> temp=[];
> tempa = find(n < cell2mat(dataIn{2,1}(:,3)));
> tempb = find(n >= cell2mat(dataIn{2,1}(:,2)));
> aCount = 0;
> for a=1:size(tempb)
>
> if isempty(find(tempa == tempb(a), 1)) == 1
> %do nothing
> else
> aCount = aCount +1;
> temp(aCount) = find(tempa == tempb(a));
> end
>
> end
> clear tempa
> clear tempb
> count(nCount) = size(temp,2);
>
>
> end
>
> Sorry if the question is not well described. Any help is appreciated.
- - - - - - - - -
If I understand what you want, this might save some time:
d2 = cell2mat(dataIn{2,1}(:,2));
d3 = cell2mat(dataIn{2,1}(:,3));
t = timeStart:1/24:timeEnd;
for k = 1:length(t)
count(k) = sum(d2<=t(k) & t(k)<d3);
end
Roger Stafford
|