Effacer les filtres
Effacer les filtres

How to reverse a subarray of an array

4 vues (au cours des 30 derniers jours)
Amine Ne
Amine Ne le 20 Août 2018
Commenté : Amine Ne le 20 Août 2018
Reversing element order in a selected sub sequence?
Two positions are selected randomly then element positions between these two positions are reversed.
For example: A = [1 2 3 4 5 6 7 8 9 10]; idx = randi(10, 1, 2) = [3 8]; 'A' will be become A = [1 2 8 7 6 5 4 3 9 10]
Thank you

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 20 Août 2018
A([1:min(idx)-1,max(idx):-1:min(idx),max(idx)+1:10])
  1 commentaire
Amine Ne
Amine Ne le 20 Août 2018
Thank you Fangjun Jiang, it works well

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by