How to reverse a subarray of an array

6 visualizaciones (últimos 30 días)
Amine Ne
Amine Ne el 20 de Ag. de 2018
Comentada: Amine Ne el 20 de Ag. de 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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 20 de Ag. de 2018
A([1:min(idx)-1,max(idx):-1:min(idx),max(idx)+1:10])

Más respuestas (0)

Categorías

Más información sobre Array Geometries and Analysis en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by