Find Consecutive numbers and print value in next collumn
Mostrar comentarios más antiguos
Hi,
I have a table of 4 collumns with over a million rows. In collumn 4 I have a collumn that iis based on logic (when the temperature in collumn 3 exceeds a given value the entry in collumn 4 will be one and when it does not exceed it will be 0).
In collumn 5 I would like to have a count of the number of consectutive values placed in the row of the final 1.
I have used the following to get a vector of containing the consecutive counts, but I am unsure how to get them to print in collumn five at the end of each cosecutive set
f = find(diff([0,exceedlogic,0]==1));
p = f(1:2:end-1); % Start indices
y = f(2:2:end)-p; % Consecutive ones’ counts
2 comentarios
David Hill
el 13 de Jul. de 2021
A simple example showing a few rows would be helpful
Patrick Lonergan
el 13 de Jul. de 2021
Respuesta aceptada
Más respuestas (1)
David Hill
el 13 de Jul. de 2021
Simple loop works
c=0;
f(:,6)=0;
for k=1:size(f,1)
if f(k,5)==1
c=c+1;
f(k,6)=c;
else
c=0;
end
end
1 comentario
Patrick Lonergan
el 14 de Jul. de 2021
Categorías
Más información sobre Quadcopters and Drones en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

