How to shift entries in a vector by the value of the number in that entry?
Ältere Kommentare anzeigen
For example, if i have a vector
T = [0, 0, 4, 0, 7, 0, 0, 5, 0, 9]
How would i go about moving every entry to the right by the number in that entry?
Ie: T(3) 4 spaces to the right, T(4) 0 spaces to the right, and T(8) 5 spaces to the right so that it overwrites the orginal T(3).
Thanks.
1 Kommentar
Jan
am 19 Mär. 2021
What is the wanted output for [1,2,3] ?
Akzeptierte Antwort
Weitere Antworten (1)
Hi Tim David,
T = [0, 0, 4, 0, 7, 0, 0, 5, 0, 9];
shiftme = @(A,nShift) circshift(A,A(nShift));
shiftme(T,3)
Kind regards,
Robert
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!