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

1 回表示 (過去 30 日間)
omar th
omar th 2022 年 7 月 15 日
コメント済み: 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]

採用された回答

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 Center および File ExchangeGet 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