KatyB
KatyB

Reputation: 3990

find the range for specific data from a time series

I have a time series:

d = [transpose(floor(1+1/24:1/24:366)),1+(30-1).*rand(8760,1)];

Where the first column refers to day of year and the second column refers to the data. The data are measured in hours but are floored here to represent the day of measurement.

I want to split the data into different cells, where each cell shows the data for the different days where the start time of the data varies. For example, if I select one specific day from the example:

dat = d(d(:,1)==2,:);

And I want to split this into different cells according to the following statement:

Res = 1:11;
starti = arrayfun(@(x)dat(x:end,:),Res,'un',0);

which gives me the same series but with different starting points. I then find the range of values by:

rng = cellfun(@(x)range(x(:,2)),starti,'un',0);

How would I perform the same method but for the entire series i.e.

dat = d;

thanks for your help

Upvotes: 1

Views: 445

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38052

Why not just use a for loop?

R = d(1,1):d(end,1);
rng = cell(numel(R),1);
for ii = R

    dat = d(d(:,1)==ii,:)    

    Res = 1:11;
    starti = arrayfun(@(x)dat(x:end,:),Res,'un',0)

    if ~any(cellfun('isempty', starti))            
        rng{ii} = cellfun(@(x)range(x(:,2)),starti); end        
end

Upvotes: 2

Related Questions