Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse array order in Matlab

Tags:

arrays

matlab

If I have an array

>> c = 1:10

c =

 1     2     3     4     5     6     7     8     9    10

How do I reverse the last five elements, so that my new array is

c =

 1     2     3     4     5     10    9     8     7     6

Thank you,

like image 327
B. Z. Avatar asked Jan 24 '26 16:01

B. Z.


2 Answers

Need to use array merge and flip for subarray

A = 1:10
A = [A(1:5),fliplr(A(6:10))]
like image 111
Abhi Avatar answered Jan 27 '26 09:01

Abhi


You can try the following code, it uses the increment index :

d = [c(1:5), c(10:-1:6)]
like image 24
oro777 Avatar answered Jan 27 '26 08:01

oro777



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!