Borrar filtros
Borrar filtros

Loop through files of different length

2 visualizaciones (últimos 30 días)
Emu
Emu el 6 de Oct. de 2022
Comentada: dpb el 6 de Oct. de 2022
I am trying to loop through some data files of differing length, but at the moment I have to set the length manually for each file, so my code keeps breaking:
hrsInf(1,1) = sum(ECGdata(1:h,1)==0)/h*100;
hrsInf(2,1) = sum(ECGdata(h+1:2*h,1)==0)/h*100;
hrsInf(3,1) = sum(ECGdata(2*h+1:3*h,1)==0)/h*100;
hrsInf(4,1) = sum(ECGdata(3*h+1:4*h,1)==0)/h*100;
hrsInf(5,1) = sum(ECGdata(4*h+1:5*h,1)==0)/h*100;
hrsInf(6,1) = sum(ECGdata(5*h+1:6*h,1)==0)/h*100;
and so on, where h is one hour (with a 250psec sampling rate). How can I loop through each file to the maximum number of whole hours?

Respuesta aceptada

dpb
dpb el 6 de Oct. de 2022
When you compute what h is in samples (if sample rate varies, otherwise just set it as a constant), then
[R,C]=size(ECGdata);
N=fix(R/h);
tmp=reshape(ECGdata(1:N*h,1),h,[]);
hrsInf=sum(tmp==0)/h*100;
  2 comentarios
Emu
Emu el 6 de Oct. de 2022
oh my goodness thank you so much !!
dpb
dpb el 6 de Oct. de 2022
Yeah, taking advantage of knowledge of storage order and that most MATLAB functions operate by default by column can save a lot of gyrations otherwise...
Another way to do stuff similar to this if have Image TB is blockproc

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

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by