0
 clear all
    data = rand(8760,1);
    n=366;
    time=linspace(1+1/24,n,(n-1)*24)';
        %day of year
    daylims = ([100,300]);

    [row1]=find(time > daylims(1) & time < daylims(2));

From the example above I'm trying to select the data for e period given by 'daylims' and then fit that data into a vector which corresponds to 'time'. Having found the row number for the data which I need, all I'm trying to do now is to surround the 'data' with nans e.g. first row is 2377 so then I want to make row 1:2377 as nan and as the last row is 7175 so I want to make row 7175:end as nan (end is 8760).

This can easily be done by moving the values around manually but I was hoping of a more efficient method. Let me know if I'm not clear.

2 Answers 2

1

I often do it like this:

good_data = (time > daylims(1) & time < daylims(2)); 
data(~good_data)=NaN;

Note I do not use find but logical indexing instead.

Sign up to request clarification or add additional context in comments.

Comments

0

Did you tried this approach?

data(1 : 2377) = nan;
data(7175 : end) = nan;

1 Comment

yes I did this, but I was looking for a more sophisticated approach. If I would need to do this for a larger dataset, then it would be very time consuming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.