MATLAB Answers

Andrei Stefan

Identify gaps between data in column structure, and , for differences bigger than a defined value, find start and end index of the two values

Asked by Andrei Stefan
on 22 Aug 2014
Latest activity Commented on by Andrei Stefan
on 22 Aug 2014

Hi to everybody. The Question is rather confusing but i will explain it. I have a data structure(data_struct)with 100 trials organised in columns. Each trial has another structure within called Eye_Data.The first column in Eye_Data is the 'time'. The gaps between the values are usually 2 ms. Some are 4 ms. I am trying to identify the gaps bigger than 2 ms and plot them on a 2D graph. This is working ok. But if i am trying to plot on timeseries plot, i need to find the two values that have 4 ms between them, so i can declare the start and end of a timeseries event. Please help me in this matter. Thank you The simple code is shown below

data_struct = handles.data_struct;
Selected_Trials = handles.Selected_Trials;
for bli = data_struct(Selected_Trials).Eye_Data(:,1);
 BLINK = diff(bli);
 if  BLINK>2;
      str = sprintf('No Blinks on trial:%d',trial);



No products are associated with this question.

1 Answer

Answer by the cyclist
on 22 Aug 2014
 Accepted answer

Do you mean you are trying to find the index to the positions where diff(bli) > 2?

If so, you should be able to use



Hi.Thank you for the quick reply.I managed to get the difference between the elements.Now i need to find the position/index of the terms that give a difference >2, for i need to declare them as the start and end of a timeseries event. I want to plot them as events on a timeseries plot.

Isn't the find() command exactly what you need, then?

find([2 2 2 2 2 2 4 2 2 2 2 2 4 2]>2)

is going to give

[7 13]

which tells you where the 4's are.

Sorry. I just realised that your answer is what i am looking for.

Thank you

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!