필터 지우기
필터 지우기

Loop through files of different length

조회 수: 2 (최근 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 CenterFile Exchange에서 Loops 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