Extract the bigger number of values from the previous one in an array

1 回表示 (過去 30 日間)
Ali Najem
Ali Najem 2022 年 9 月 28 日
コメント済み: Ali Najem 2022 年 9 月 28 日
Dear experts,
I want to do this kind of loop
Data = rand(1,15);
for i=1:15
if Data(i) < Data(i+1)
X =10;
else
X=0;
end
end
X;
I suppose to get 15 values of X between 10 and 0 but I obtained this error
Index exceeds the number of array elements. Index must not exceed 15.
how can i proceed this loop into
  1 件のコメント
Matt J
Matt J 2022 年 9 月 28 日
I suppose to get 15 values of X between 10 and 0 but I obtained this error
There can't be 15 values, because when i=15, Data(i+1) doesn't exist.

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

採用された回答

Matt J
Matt J 2022 年 9 月 28 日
編集済み: Matt J 2022 年 9 月 28 日
Easier to do,
Data = rand(1,15)
Data = 1×15
0.5961 0.1403 0.0904 0.4693 0.6848 0.1834 0.0516 0.4032 0.2979 0.5497 0.9613 0.9228 0.9208 0.8610 0.7979
X=10*(diff(Data)>0)
X = 1×14
0 0 10 10 0 0 10 0 10 10 0 0 0 0
  1 件のコメント
Ali Najem
Ali Najem 2022 年 9 月 28 日
Thank you sir for your prompt answer.
I apprecaited.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by