0

I have a series of datasets each one about 1032 x 4. With the programme I have now I can find the time at which a certain event is happening (I did that though structures). And the output I get is :

startTime: [1 84 111 251 450 482 613 660 787 951 956]
 endTime: [5 90 112 252 451 485 619 661 788 952 961]

This output tells me from which row to which row this event that I am interested in is happening. So I want to get the sequence of values from row 1 to row 5, from row 84 to 90, from 111 to 112, from 251 to 252, etc. I can do that manually by typing time(1), time(5), time(84), time(90) so I can calculate the duration of the events. But is there any way to do that automatically?

Help please !! It sounds like an easy thing to do but it is driving me crazy.

Thanks in advance,

The code I have so far is:

function DetectEvent = DetectEvent(inputData, ColumnNumbers)
%ColumnNumbers = 1 contains Time
%ColumnNumbers = 2 contains Position
%ColumnNumbers =3 contains velocity
%ColumnNumbers=4 contains accelereation

eventNow = false;
event.startTime = []; % initialise
event.endTime = []; % initialise
for i = 1: length(inputData)
if abs(inputData(i,ColumnNumbers.velocity)) == 0 
    if ~eventNow
        eventNow = true;
        thisevent.startTime = i;
    end
else
    if eventNow
        eventNow = false;
        thisevent.endTime = i - 1;
        event.startTime = [event.startTime, thisevent.startTime];
        event.endTime = [event.endTime, thisevent.endTime];
    end
end
end
Flowers
  • 59
  • 1
  • 2
  • 12

1 Answers1

0

You can use startTime and endTime as indices combined with the colon operator (:).

For example, to get the events recorded at i (e.g. started at startTime(i) and ended at endTime(i) you can use (assuming your 1032x4 matrix is called data):

events=data(startTime(i):endTime(i),:);

This will place into events all rows from startTime(i) to endTime(i) in the data matrix.

Marc Claesen
  • 16,778
  • 6
  • 27
  • 62