필터 지우기
필터 지우기

How to reverse a subarray of an array

조회 수: 2 (최근 30일)
Amine Ne
Amine Ne 2018년 8월 20일
댓글: Amine Ne 2018년 8월 20일
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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 8월 20일
A([1:min(idx)-1,max(idx):-1:min(idx),max(idx)+1:10])
  댓글 수: 1
Amine Ne
Amine Ne 2018년 8월 20일
Thank you Fangjun Jiang, it works well

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by