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

Thread Subject:
Selecting a specific number of rows and Dividing data into segments of the same length

Subject: Selecting a specific number of rows and Dividing data into segments of the same length

From: swinnn

Date: 17 Nov, 2013 23:30:12

Message: 1 of 4

I have several hundred thousands data in one column in MyData.mat file, each measurement was recorded in a specific time. I can read the time of each measurement, e.g.:
datestr(MyData(10),'dd-mm-yyyy HH:MM:SS AM');
and I got answer in 10th row the time of measurement was 10-01-2012 12:10:04 PM

Let's say I want to recall only 32 seconds out of these data, e.g. 12:21:07 til 12:21:39 PM. How can I do it?

By now I found I could just recall the rows which contain these 32 seconds (12:21:07-12:21:39 PM), e.g.:
X=MyData(144:1220,1);
but it takes lots of time to identify the rows of my interest. Is there any easier way/commend to recall the data by the time, eg. start 12:21:07, finish 12:21:39? I have tried to use logical indexing but I haven't found any solution yet.

Then, my another problem is, I need to divide these 32 seconds into 2.56 seconds segments.
I have tried to use C = mat2cell. It works if I specify the parameters (number of rows ), but Im looking for some other general function that divides different length of data (e.g. 32 seconds -as above, 40 seconds, 35 seconds, 41 seconds etc) always in small segments of 2.56 seconds, without setting different parameters (number of rows , submatrices) each time.

Sampling frequency was 100 Hz

Does anybody have any idea and could help me, please?

Subject: Selecting a specific number of rows and Dividing data into

From: TideMan

Date: 18 Nov, 2013 00:57:36

Message: 2 of 4

On Monday, November 18, 2013 12:30:12 PM UTC+13, swinnn wrote:
> I have several hundred thousands data in one column in MyData.mat file, each measurement was recorded in a specific time. I can read the time of each measurement, e.g.:
>
> datestr(MyData(10),'dd-mm-yyyy HH:MM:SS AM');
>
> and I got answer in 10th row the time of measurement was 10-01-2012 12:10:04 PM
>
>
>
> Let's say I want to recall only 32 seconds out of these data, e.g. 12:21:07 til 12:21:39 PM. How can I do it?
>
>
>
> By now I found I could just recall the rows which contain these 32 seconds (12:21:07-12:21:39 PM), e.g.:
>
> X=MyData(144:1220,1);
>
> but it takes lots of time to identify the rows of my interest. Is there any easier way/commend to recall the data by the time, eg. start 12:21:07, finish 12:21:39? I have tried to use logical indexing but I haven't found any solution yet.
>
>
>
> Then, my another problem is, I need to divide these 32 seconds into 2.56 seconds segments.
>
> I have tried to use C = mat2cell. It works if I specify the parameters (number of rows ), but Im looking for some other general function that divides different length of data (e.g. 32 seconds -as above, 40 seconds, 35 seconds, 41 seconds etc) always in small segments of 2.56 seconds, without setting different parameters (number of rows , submatrices) each time.
>
>
>
> Sampling frequency was 100 Hz
>
>
>
> Does anybody have any idea and could help me, please?

Define your start and finish dates:
t1=datenum('10-01-2012 12:21:07','dd-mm-yyyy HH:MM:SS');
t2=datenum('10-01-2012 12:21:39','dd-mm-yyyy HH:MM:SS');
% Now find the data between
indx=MyData(:,1) >= t1 & MyData(:,1) <= t2;
So the data you want are in
MyData(indx,:)

And one way to find the data at particular times:
ti=t1:32/86400:t2; % There are 86400 s in a day
yi=interp1(MyData(:,1),MyData(:,2),ti);

Subject: Selecting a specific number of rows and Dividing data into

From: swinnn

Date: 20 Nov, 2013 00:59:15

Message: 3 of 4

Hi, thanks for tips.
I have tired to use this (to define start and finish dates) but as the answer for MyData(indx,:), I get empty matrix. I dont know whats wrong

Subject: Selecting a specific number of rows and Dividing data into

From: swinnn

Date: 20 Nov, 2013 01:29:09

Message: 4 of 4

My code:

load('MyData.mat')
P=RightLimb

% Define start and finish dates:
t1=datenum('13-01-2010 9:32:04 AM','dd-mm-yyyy HH:MM:SS');
t2=datenum('13-01-2010 9:32:22 AM','dd-mm-yyyy HH:MM:SS');

% Now find the data between
indx=P(:,2) >= t1 & P(:,2) <= t2; %data of my interests are in 2nd column in P

%So the data you want are in
P(indx,:)

% I got answer:

ans =
   Empty matrix: 0-by-4

%And one way to find the data at particular times:
ti=t1:18/86400:t2; % here are 86400 s in a day
yi=interp1(P(:,2), P(:,3),ti);

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us