필터 지우기
필터 지우기

How to find a the point where the loop is broken?

조회 수: 2 (최근 30일)
Kalpha.mc
Kalpha.mc 2020년 11월 1일
답변: Walter Roberson 2020년 11월 1일
I need to find where the diffence starts to be less then 0.01 which should me n = 12
But i can't seem to make it show up by itself?
terms = [2.0000 2.5216 2.6042 2.6379
2.2500 2.5465 2.6130 2.6424
2.3704 2.5658 2.6206 2.6464
2.4414 2.5812 2.6272 2.6500
2.4883 2.5937 2.6329 2.6533];
for index = 1
if terms >= 2
n = abs(terms);
t = diff(n);
elseif t < 0.01
n = find(t);
disp(n)
break
end
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 1일
if terms >= 2
That is.
if all(terms >= 2)
which is important because some elements are true and some are false.
Note that you are within a for loop but you are not using the index of the loop there and the loop does not change the contents of the variable, so it is not possible to have different outcomes on different iterations of the loop. If, hypothetically, you were making the correct if test, then you would better off removing the loop. Perhaps you are making the wrong test.
You need to define whether you want to treat the entire matrix like a vector or if you want to give an answer for each row or each column.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by