Azzera filtri
Azzera filtri

Loop through files of different length

2 visualizzazioni (ultimi 30 giorni)
Emu
Emu il 6 Ott 2022
Commentato: dpb il 6 Ott 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?

Risposta accettata

dpb
dpb il 6 Ott 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 Commenti
Emu
Emu il 6 Ott 2022
oh my goodness thank you so much !!
dpb
dpb il 6 Ott 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by