フィルターのクリア

How to get a for loop to update its iterations on a variable that can change.

2 ビュー (過去 30 日間)
Eric Cheatwood
Eric Cheatwood 2017 年 11 月 11 日
回答済み: Image Analyst 2017 年 11 月 11 日
Hi, I am working on a project that evaluates an EKG and this particular set of code I am having problems with checks if there is a t wave in between each set of QRS complexes. If no T is present, the QRS is consider a false positive and removed from the set. The problem I am having is if a QRS is removed, the for loop goes to the original length of the array. Is there a way to get the for loop to suspend its iterations early if the length of locqrs is shortened within the loop.
for n = 1:length(locqrs)-1
%Finding if there is a T between QRS n and QRS n+1.
tpres = find(loct > locqrs(n) & loct < locqrs(n+1));
%If else that removes QRS complex if tpres is zero.
if isempty(tpres) == 1
locqrs(n) = [];
ampqrs(n) = [];
widthqrs(n) = [];
promqrs(n) = [];
qrstelim = qrstelim +1;
else
end
%NN represents the R to R interval of the ECG signal.
NN(n) = locqrs(n+1) - locqrs(n);
n = n + 1;
end
  1 件のコメント
KSSV
KSSV 2017 年 11 月 11 日
YOu can put a if condition with break if you want to come out of loop.

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

採用された回答

Image Analyst
Image Analyst 2017 年 11 月 11 日
You can't. If you change a loop iterator value within the for loop, it will change for the remainder of that iteration, but once it hits the "end" and begins the next iteration, it will take on the value it would have anyway, basically ignoring what you did.
What you need to do is to convert the for loop into a while loop. With a while loop, you can change variables inside.

その他の回答 (1 件)

Yogananda Jeppu
Yogananda Jeppu 2017 年 11 月 11 日
Looks like you have the data and you are doing post processing. Try not to use the for loop. Use the find for the complete array. You will get a set of indices. Remove them.

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by