How can I rearrange a vector?

1 次查看(过去 30 天)
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!

采纳的回答

Jan
Jan 2022-2-15
编辑:Jan 2022-2-15
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by