how can I choose values from a vector ascendingly and concequently ?

1 次查看(过去 30 天)
X = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479]

采纳的回答

Voss
Voss 2022-7-15
X = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479]
X = 1×20
-28.6479 -27.5000 -18.3300 -13.7500 -11.0000 -9.1600 -7.8500 -6.8700 -6.1100 -5.5000 5.5000 6.1100 6.8700 7.8500 9.1600 11.0000 13.7500 18.3300 27.5000 28.6479
% choose three consecutive elements from X, starting with element 5:
choice = X(5:7)
choice = 1×3
-11.0000 -9.1600 -7.8500
  2 个评论
omar th
omar th 2022-7-15
first thank you for your fast response, but I want to choose only one value each iteration because this vector inside while loop. for example, in the first step I want choose -28.6479 in the second step I want to choose -27.5 and so forth up to choosing the final value in the vector which is -28.6479
Voss
Voss 2022-7-15
X = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479]
X = 1×20
-28.6479 -27.5000 -18.3300 -13.7500 -11.0000 -9.1600 -7.8500 -6.8700 -6.1100 -5.5000 5.5000 6.1100 6.8700 7.8500 9.1600 11.0000 13.7500 18.3300 27.5000 28.6479
for current_index = 1:numel(X)
choice = X(current_index)
end
choice = -28.6479
choice = -27.5000
choice = -18.3300
choice = -13.7500
choice = -11
choice = -9.1600
choice = -7.8500
choice = -6.8700
choice = -6.1100
choice = -5.5000
choice = 5.5000
choice = 6.1100
choice = 6.8700
choice = 7.8500
choice = 9.1600
choice = 11
choice = 13.7500
choice = 18.3300
choice = 27.5000
choice = 28.6479

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by