Loop through files of different length

3 ビュー (過去 30 日間)
Emu
Emu 2022 年 10 月 6 日
コメント済み: dpb 2022 年 10 月 6 日
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?

採用された回答

dpb
dpb 2022 年 10 月 6 日
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 件のコメント
Emu
Emu 2022 年 10 月 6 日
oh my goodness thank you so much !!
dpb
dpb 2022 年 10 月 6 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by