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

3 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 1 Nov 2020
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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!