Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to filter data?

Asked by Thor on 16 Jan 2013

Dear all,

I want to filter a matrix by its date vector. The datevector has the format: dd.mm.yyyy HH:MM:SS. I want to sum up all the data with the same month and year. How can I do that?

0 Comments

Thor

Products

No products are associated with this question.

1 Answer

Answer by Jan Simon on 16 Jan 2013
Accepted answer
dateAsString = {'31.02.2013 11:22:33'; '31.05.2013 11:22:33'}
dateAsVector = datevec(datestr, 'dd.mm.yyyy HH:MM:SS');
yearAndMonth = 100 * dateAsVector(:, 1) + dateAsVector(:, 2);

Now you get values like [201302, 201305] and summing can be done by accumarray directly.

2 Comments

Walter Roberson on 16 Jan 2013

You would probably not want to use those values as direct subscripts into accumarray: you would probably want to unique() them and use the indices. Otherwise your array is going to end up being up to 240000 long with not many entries used.

Jan Simon on 16 Jan 2013

You are right, Walter, and even for a FOR loop approach using the indices obtained by UNIQUE is better.

Jan Simon

Contact us