Why does my for loop cause MATLAB to not stop running?
1 回表示 (過去 30 日間)
古いコメントを表示
The code I am writing has as its purpose to analyse some data and plot it accordingly. My data consists of a series of consecutive measurements but every now and then there is a malfunction in the physical system that causes a measurement to be wrong (this event is not regular but purely aleatory).
I am able to find which measurement is wrong before plotting them, and therefore I am trying to elimiate such measurements, but sometimes there is no wrong measurements.
I am trying to put 3 plots together, 2 with errors at 83 and 5, and one without errors (characterised as 0). I wrote the following for loop with if statements:
sample = [name1, name2, name3];
num = [83, 5, 0];
for x = 1: length(sample)
if num(x) ~= 0
for i = 1:(num(x)-1)
a(i)=sample(x).impulse_P2P(i);
end
for i=(num(x)+1):length(sample(x).impulse_P2P)
a(i-1)=sample(x).impulse_P2P(i);
end
sample(x).impulse_P2P=a;
elseif num(x) == 0
for i = 1:length(sample(x).impulse_P2P)
a(i)=sample(x).impulse_P2P(i);
end
sample(x).impulse_P2P=a;
end
But for some reason when I run this bit of code, it never stops running, I think it might be stuck in a loop or something like that but I don't know why.
Any help would be greatly appreciated.
0 件のコメント
採用された回答
Matt J
2022 年 1 月 26 日
編集済み: Matt J
2022 年 1 月 26 日
In the code as you've posted it, the for-loop is never closed by an "end". That would prevent it from continuing to the next iteration.
2 件のコメント
Matt J
2022 年 1 月 26 日
You're quite welcome, but please Accept-click the answer to indicate that it resolved the question.
Please also go back to your previous posts and do likewise
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!