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

2 次查看(过去 30 天)
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