Collecting information in columns if X

Hi,
I have a file that contains 5 columns of data, where the 3 first columns contains the date (year, month and day). The last two contains data I want to use.
What I want to do: Gather info from column 4 in a new sheet(data table) if the year, date and day matches up.
For example: I want to gather all data from 1th January to 31th December, 2009. When it's done I want it to continue to the next year, and so on.
Any ideas?

1 Comment

What does 'gather' mean? get the sum, mean, all the values?
The best thing would be for you to give an example of inputs and desired output.

Answers (1)

I'm not sure what you mean by gather. In the simplest sense:
dailydata = [2008 12 30 1 5;
2008 12 31 5 7;
2009 1 1 2 6;
2009 1 5 3 4;
2009 10 10 9 8;
2009 11 30 6 1;
2010 1 1 2 6];
dt = datetime(dailydata(:, 1:3));
requireddata = dailydata(dt >= datetime(2009, 1, 1) & dt <= datetime(2009, 12, 31), :)
Note that if you want to do that for several ranges, there are more efficient ways than a loop, but we would need to know what output format you want.

This question is closed.

Asked:

on 23 Oct 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!