How can I rearrange a vector?
3 views (last 30 days)
Show older comments
I have a vector
a = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9];
How can I rearrage it to
a = [0 0 0 0 0 4 3 2 1 0 1 2 3 4 0 0 0 0 0];
Thank you!
0 Comments
Accepted Answer
Jan
on 15 Feb 2022
Edited: Jan
on 15 Feb 2022
Some bold guesses of what you want to achieve:
aa = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9];
a = aa;
a(a >= 5) = 0
a = aa;
a(~ismember(a, 1:4)) = 0
a = aa;
a(ismember(a, 5:9)) = 0
a = aa;
a([1:5, end-4:end]) = 0
a = aa;
n = numel(a);
a(abs((1:n) - (n + 1)/2) >= 5) = 0
There is an infinite number of methods to produce the wanted output based on the given input. The current explanations are not enough to find the general solution.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!