While loop to get a specific section of data

17 visualizaciones (últimos 30 días)
Sydney Kehoe
Sydney Kehoe el 8 de Jun. de 2021
Comentada: Sydney Kehoe el 9 de Jun. de 2021
resp = [];
ii = 1;
n = 720000;
go = 0;
while ii < length(acq2.data(:,4))
if acq2.data(ii,4) > 1 && go == 0
resp(ii) = acq2.data(ii,3);
go = 1;
else
ii = ii + 1;
end
jj = 1;
if go == 1 && jj < n
resp(ii) = acq2.data(ii,2);
jj = jj + 1;
end
if go == 1
ii = ii + 1;
end
end
So basically what I am trying to do here is use column 4 data (which ranges from 0.1 when it is resting and it jumps up to 5 when it is active) so I want to start moving data into the new array at the first instance ii when the data in column 4 jumps up to 5 (in this case when it is greater than 1). Since I only want this to happen once I made sure go at first equals 0 and when this condition is first met it then becomes g=1 so that it does not repeat that aspect of the code. So ideally this will create a new column of data in the new array resp where it starts at some point ii where the data in column 4 first is greater than 1 and then it ends some 720000 points later.
  1 comentario
Sydney Kehoe
Sydney Kehoe el 8 de Jun. de 2021
For example if ii = 5779 where acq2.data(:,4) at that point is 5 the new array resp =[] would start being filled at row 5779 continuing through ii = 725779 (since n = 720000). I'm thing the go scenario will ensure that the acq2.data>1 only has to be met once. As of right now this code seems to start inputting data into a new array when acq2.data>1 but then altnerates between listing values and zeroes from there on out.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 9 de Jun. de 2021
Editada: dpb el 9 de Jun. de 2021
Far easier if you would attach a (small) sample of the dataset, but the general idea would be
thresholdUp=1; % set the rising threshold level
thresholdDn=0.1; % and the falling
i1=find(Data(:,4)>=thresholdUp,1); % the first above threshold
i2=find(Data(i1:end,4)<thresholdDn,1)+i1; % the first value below drop threshold after start
newData=Data(i1:i2,:); % save the data between events
  1 comentario
Sydney Kehoe
Sydney Kehoe el 9 de Jun. de 2021
Thanks for your help! It ended up being something closer to what I have but thank you for your time all the same!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by