Info

This question is closed. Reopen it to edit or answer.

How to sort a matrix into groups according to the times at which they occur?

1 view (last 30 days)
Hello,
I have a matrix called pRatio1 which has dimensions (4140,2). The first column of the matrix relates to time and the second column of the matrix relates to a data observation at each corresponding time. The data observations are random and not sampled at a set rate.
The time is of form 0.00 represents midnight, 0.25 quarter past midnight, 0.5 half past midnight all the way up to 23.99.
What I want to do is write a piece of code that would split the data into five minute periods. So, for example, all data that falls between midnight and five past midnight would become part of a new matrix.
Any ideas of how to do this?
Thanks
Rory
  1 Comment
dpb
dpb on 4 Nov 2013
If you mean the above literally, then it's simply
y=x(iswithin(x(:,1),0,5/24),:); % include the timestamp, too
y=x(iswithin(x(:,1),0,5/24),2); % just the data instead
The question is, do you care/need the day info or just that it's during the desired fraction of a day when collected irrespective of day?
iswithin is my helper function
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
%
flg= (x>=lo) & (x<=hi);
which makes writing such logic expressions easier by hiding the complexity of the test at a lower level.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!