How can I rearrange a vector?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Jan
am 15 Feb. 2022
Bearbeitet: Jan
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!