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

1 Ansicht (letzte 30 Tage)
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]

Akzeptierte Antwort

Voss
Voss am 15 Jul. 2022
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 Kommentare
omar th
omar th am 15 Jul. 2022
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 am 15 Jul. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by