Creating a loop to determine at which iteration an error has occurred

조회 수: 1 (최근 30일)
Lets say i have a single column matrix
A = [1;2;3;4;5;6;7;13;14;15]
how do i find out at which point there is a jump >5 using a loop and logic to determine the row at which the erroneous increase in data occured

채택된 답변

William
William 2021년 1월 17일
You don't necessarily need a loop for this. You can use B = diff(A) to return the differences between each pair of successive values of A, and then find(B > 1) to locate the ones that are larger than 1.
However, if you just wanted to know how to use a loop to do this, you could try
bad = [];
for j = 1:length(A)-1
d = A(j+1)-A(j);
if d > 1
bad = [bad j];
end
end
This would compile an array named 'bad' containing the location of all jumps in the value.

추가 답변 (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