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

1 visualización (últimos 30 días)
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]

Respuesta aceptada

Voss
Voss el 15 de Jul. de 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 comentarios
omar th
omar th el 15 de Jul. de 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 el 15 de Jul. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by