how to shift specific elements in a array to a specific position?
Show older comments
I have an arry A = [1,2,3,4,5,6,7,8,9,10]. I want specific elements to shift the order but remain with the same elements. E.x. I want 3 elements (7,8,9) in A to shift 3 postions to the left to get an array B = [1,2,3,7,8,9,4,5,6,10]
Thanks,
Nur
1 Comment
Manali Gupta
on 21 Jun 2019
Hi,
I assume that you know the index from which you need to shift.
Here,
a=1:10;
k=7;i=3;
b=[a(1:k-i-1) a(k:k+i-1) a(k-i:k-1) a(k+i:end )];
Accepted Answer
More Answers (1)
Nurahmed
on 21 Jun 2019
0 votes
Categories
Find more on LaTeX in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!