How can write loop for this algorithm?

1 回表示 (過去 30 日間)
Sakdinon Nopparit
Sakdinon Nopparit 2020 年 8 月 24 日
コメント済み: Jan 2020 年 8 月 30 日
If i have A={1 1 2 2 3 3 3 4 4 8 9 10}
How can i run data from 1
after that i plus that data with 1
if data that i got is in A it will plus 1
if i not it will stop loop and show that outcome too
from my example it will stop at 4 and show 4 as a outcome

回答 (1 件)

Jan
Jan 2020 年 8 月 25 日
編集済み: Jan 2020 年 8 月 25 日
I'm not sure, because the question is not completely clear to me. Perhaps:
A = [1 1 2 2 3 3 3 4 4 8 9 10];
d = diff(A);
v = find(d > 1, 1, 'first');
if isempty(v)
disp('Number not found')
else
A(v)
end
  2 件のコメント
Sakdinon Nopparit
Sakdinon Nopparit 2020 年 8 月 26 日
thank you
let me give you another example
if A=[-0.8687 -0.8677 -0.8677 -0.8667 -0.2547]
and i start from the first data and keep adding 0.001 until it not found the data in this array
from my example it will adding 0.001 until -0.8657 and it will stop becuase -0.8657 is not in this array
after that show previous data
Jan
Jan 2020 年 8 月 30 日
What exactly is "the previous data"? Please explain explicitly, which output you want.
A = [-0.8687 -0.8677 -0.8677 -0.8667 -0.2547]
d = diff(A);
% d = [0.0010 0 0.0010 0.6120]
So do you search for the first number, which is greater than 0.001? Then use the already suggested code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by