フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by