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

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by